首页 > 代码库 > 7.给图像划分区域

7.给图像划分区域

void Test_DrawRectangelOnImage(int _width, int _height)
{
	Mat g_srcImage=imread("D:\\OpenCV Projects\\OpenCV_Test_Image\\7.jpg");
	int width=g_srcImage.size().width;//图像的宽度
	int height=g_srcImage.size().height;//图像的高度
	int cols=(int)width/_width;//分区的列数
	int rows=(int)height/_height;//分区的行数
	Point linePointA,linePointB;
	//画竖线
	for(int i=0;i<cols;i++)
	{
		linePointA.x=i*_width;
		linePointA.y=0;
		linePointB.x=i*_width;
		linePointB.y=height;
		line(g_srcImage,linePointA,linePointB,Scalar(255,255,255));
	}
	//画横线
	for(int i=0;i<rows;i++)
	{
		linePointA.x=0;
		linePointA.y=i*_height;
		linePointB.x=width;
		linePointB.y=i*_height;
		line(g_srcImage,linePointA,linePointB,Scalar(255,255,255));
	}
	imshow("test",g_srcImage);
}

技术分享

 

7.给图像划分区域