梁山做网站的公司,虚拟会员商城网站分销,wordpress视频模型,深圳市住房和建设局官网站首页目录 一、理论基础1、八邻域2、断点检测 二、代码实现三、结果展示四、参考链接 OpenCV——八邻域断点检测由CSDN点云侠原创#xff0c;爬虫自重。如果你不是在点云侠的博客中看到该文章#xff0c;那么此处便是不要脸的爬虫。
一、理论基础
1、八邻域 图1 八邻域示意图 图… 目录 一、理论基础1、八邻域2、断点检测 二、代码实现三、结果展示四、参考链接 OpenCV——八邻域断点检测由CSDN点云侠原创爬虫自重。如果你不是在点云侠的博客中看到该文章那么此处便是不要脸的爬虫。
一、理论基础
1、八邻域 图1 八邻域示意图 图2 八邻域对应坐标关系 2、断点检测 首先将图像进行二值化然后检测以 P 1 P_1 P1为中心的它的八个领域 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9 ≤ 255 × 6 P_2P_3P_4P_5P_6P_7P_8P_9\leq255\times6 P2P3P4P5P6P7P8P9≤255×6则 P 1 P_1 P1点是一个边界点。 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9 ≥ 255 × 6 P_2P_3P_4P_5P_6P_7P_8P_9\geq255\times6 P2P3P4P5P6P7P8P9≥255×6则 P 1 P_1 P1点是一个内部点。 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9 0 P_2P_3P_4P_5P_6P_7P_8P_90 P2P3P4P5P6P7P8P90则 P 1 P_1 P1点是一个孤立点。 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9 255 P_2P_3P_4P_5P_6P_7P_8P_9255 P2P3P4P5P6P7P8P9255则 P 1 P_1 P1点是一个端点。 图3 点的类型 二、代码实现
#include opencv2/opencv.hppusing namespace std;
using namespace cv;vectorPoint breakImage(Mat src);int main()
{ // 加载RGB图片Mat colorImage, grayImage, binImage;colorImage imread(2.png);// 显示图片namedWindow(原始图像, cv::WINDOW_NORMAL); // 图像窗口函数imshow(原始图像, colorImage);// 图像二值化cvtColor(colorImage, grayImage, COLOR_BGR2GRAY);threshold(grayImage, binImage, 1, 255, THRESH_BINARY);vectorPointP;P breakImage(binImage);int nsize P.size();Mat temp Mat::zeros(binImage.size(), CV_8UC3);// 用圆圈出端点for (int i 0; i nsize; i){circle(temp, P[i], 10, Scalar(0, 255, 0));}Mat circleadd;addWeighted(temp, 1, colorImage, 1, 0, circleadd);imwrite(端点.png,circleadd);namedWindow(circleadd, cv::WINDOW_NORMAL);imshow(circleadd, circleadd);waitKey(0);}
#pragma region//8邻域提取端点
vectorPoint breakImage(Mat src)
{vectorPoint pointxy;Point ptPoint;Size size src.size();int nSize;for (int i 1; i size.height - 1; i){uchar* dataPre src.ptruchar(i - 1);uchar* dataCurr src.ptruchar(i);uchar* dataNext src.ptruchar(i 1);for (int j 1; j size.width - 1; j){// p9 p2 p3 // p8 p1 p4 // p7 p6 p5int p1 dataCurr[j];if (p1 ! 255) continue;int p2 dataPre[j];int p3 dataPre[j 1];int p4 dataCurr[j 1];int p5 dataNext[j 1];int p6 dataNext[j];int p7 dataNext[j - 1];int p8 dataCurr[j - 1];int p9 dataPre[j - 1];if (p1 255){if ((p2 p3 p4 p5 p6 p7 p8 p9) 255){ptPoint.x j;ptPoint.y i;pointxy.push_back(ptPoint);printf(端点的坐标为x:%d y:%d\n, j, i);}}}}nSize (int)pointxy.size();printf(提取端点个数:%d\n, nSize);return pointxy;
}
#pragma endregion三、结果展示 四、参考链接
[1] 八邻域断点检测 [2] OpenCV 八领域断点检测断点缺陷修补