void groupPixels(ManagerOfGroups& manager, Bitmap bitmap) {
    for (size_t x= 0; x < bitmap.width; x++) {
        for (size_t y= 0; y < bitmap.height; y++) {
            Pixel pixel= bitmap.pixel(x,y);
            if (!manager.isInGroup(pixel)) {
                manager.createGroup(pixel);
            }
            if (x != bitmap.width - 1) {
                processNeighbor(manager,pixel, pixel.rightNeighbor());
            }
            if (y != bitmap.height - 1) {
                processNeighbor(manager,pixel, pixel.lowNeighbor());
            }
        }
    }
}
예제 #2
0
void segmentHand(cv::Mat &mask, Rect &region, const cv::Mat &depth)
{
	CV_Assert(mask.type() == CV_8UC1);
	CV_Assert(depth.type() == CV_16UC1);

	CV_Assert(mask.rows == depth.rows);
	CV_Assert(mask.cols == depth.cols);
	queue<pair<int, int> > _pixels;

	mask.setTo(EMPTY);

	pair<int, int> current = searchNearestPixel(depth, region);
	if (current.first < 0){
		//region.isIni = false;
		return;
	}

	int rowcount = depth.rows, colcount = depth.cols;


	double mean = depth.at<unsigned short>(current.first,current.second);
	int minx=depth.cols,miny=depth.rows,maxx=0,maxy=0,minz = (1<<15),maxz = 0;
	unsigned short dv = 0;
	int depthMinDiff = 50;
	int pixelcount = 1;
	_pixels.push(current);

	while((!_pixels.empty()) & (pixelcount < _maxObjectSize))
	{
		current = _pixels.front();
		_pixels.pop();

		dv = depth.at<unsigned short>(current.first,current.second);

		if (current.first < minx) minx = current.first;
		else if (current.first > maxx) maxx = current.first;
		if (current.second < miny) miny = current.second;
		else if (current.second > maxy) maxy = current.second;
		//if (dv < minz) minz = dv;
		//        else if (dv > maxz) maxz = dv;

		if ( current.first + 1 < rowcount ){
			processNeighbor(pixelcount,mean,mask,current.first + 1,current.second,depth,_pixels);
		}

		if ( current.first - 1 > -1 ){
			processNeighbor(pixelcount,mean,mask,current.first - 1,current.second,depth,_pixels);
		}

		if ( current.second + 1 < colcount ){
			processNeighbor(pixelcount,mean,mask,current.first,current.second + 1,depth,_pixels);
		}

		if( current.second - 1 > -1 ){
			processNeighbor(pixelcount,mean,mask,current.first,current.second - 1,depth,_pixels);
		}

	}
	//region.width = maxy - miny; //cols range
	//region.height = maxx - minx; //rows range
}