将轮廓划分成小块并判断每一个小块内是否有轮廓并绘制

//将轮廓区域按照行列数划分成小块区域并求每个小区域的灰度值

for (int j=0;j<layer;j++)
{
	//uchar* ptr = (uchar*)(temp4->imageData + i * roi.width/16*temp4->widthStep);
	for (int i=0;i<layer;i++)
	{
		roi1.x=i*roiw/layer;
		roi1.y=j*roih/layer;
		roi1.width=min(roiw/layer,roiw-roi1.x);
		roi1.height=min(roih/layer,roih-roi1.y);
		CalBINARYThreshold(temp5,roi1,binarythreshold);
		cout<<i << "  " <<j << "  " <<binarythreshold<<endl;

		if (binarythreshold>0.375*255)//0.275  0.24
		{
			pointflag.push_back(1);//大于这个灰度值时添加1 
		}
		else
		{
			pointflag.push_back(0);//小于这个灰度值时添加0 
		}
	}
}

IplImage* temp6=cvCreateImage(cvSize(layer*layer,layer*layer),8,1);
cvZero(temp6);//创建一张黑底的图片

int flags;

for (int i=0;i<layer;i++)
{
	//uchar* ptr = (uchar*)(temp4->imageData + i * roi.width/16*temp4->widthStep);
	for (int j=0;j<layer;j++)
	{
		flags=pointflag[i*layer+j];
		if (flags==0)
		{ 
			for (int m=layer*i;m<layer*i+layer;m++)
			{
				uchar* ptr = (uchar*)(temp6->imageData + m * temp6->widthStep);
				for (int n=layer*j;n< layer*j+layer;n++)
				{
					ptr[n]=255;//将这个点变成白色
				}
			}
		}
	}
}

猜你喜欢

转载自blog.csdn.net/kai69/article/details/78865982