Opencv实现击中击不中

《数字图像处理与机器视觉——Visual C++与Matlab实现》P289公式8-7明显错误,但是后面的图是正确的。

《数字图像处理与机器视觉》 该书下载地址:http://pan.baidu.com/share/link?shareid=3551301329&uk=1610854122

详细知识可以看击中击不中,里面的图示跟书本中介绍的差不多。

另外书本中介绍:背景的宽度选择会影响最后的计算结果,以致最终的计算结果是空集。






	Mat input_image = src;
	Mat Kernel_S1 = imread("Kernel_3.bmp");//核-数字3
	cvtColor(Kernel_S1, Kernel_S1, CV_RGB2GRAY);
	int threhold = 180;
	threshold(input_image, input_image, threhold, 255, CV_THRESH_BINARY);
	threshold(Kernel_S1, Kernel_S1, threhold, 255, CV_THRESH_BINARY);
	imshow("二值化图像", input_image);
	Mat Blankimage = Mat::ones(Kernel_S1.rows, Kernel_S1.cols, CV_8UC1);
	Mat Kernel_S2 = Blankimage * 255 - Kernel_S1;
	imshow("核1", Kernel_S1);
	imshow("核2", Kernel_S2);


	Mat hit_result, hit_result1, hit_result2;
	/// 腐蚀
	erode(input_image, hit_result1, Kernel_S1, Point(-1,-1), 1, BORDER_DEFAULT, 0);
	imshow("hit_result1", hit_result1);
	Mat BigBlankimage = Mat::ones(input_image.rows, input_image.cols, CV_8UC1);
	input_image = BigBlankimage * 255 - input_image;
	imshow("反置图像", input_image);
	/// 腐蚀
	erode(input_image, hit_result2, Kernel_S2, Point(-1,-1), 1, BORDER_DEFAULT, 0);
	imshow("hit_result2", hit_result2);
	hit_result = hit_result1 & hit_result2;
	imshow("击中击不中", hit_result);
	/// 查找击中点,验证结果
	for (int i = 0; i <input_image.rows; ++i)
	{
		uchar* data = hit_result.ptr<uchar>(i);
		for (int j = 0; j <input_image.cols; ++j)
		{
			int temp = (int)data[j];
			if (temp)
				cout << "Find "<<temp;
		}
	}


扫描二维码关注公众号,回复: 1923797 查看本文章

猜你喜欢

转载自blog.csdn.net/u012033076/article/details/22265143