- 提取轮廓
std::vector<std::vector<cv::Point> > contours;
cv::Mat image = cv::imread(“”);
只检索最外面的轮廓且用端点代替直线段(水平,竖直、对角线)
cv::findContours(image, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
// 另一种方式
vector<cv::Vec4i> hierarchy; //next,pre,child,parent
cv::findContours(mask, contours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
- 求轮廓的外接矩形
cv::Rect rect = cv::boundingRect(contours[0]);
- 判断点是否在轮廓内
cv::Point point = cv::Point(2, 2);
false只判断,true返回具体距离
double a = cv::pointPolygonTest(contours[0], point, false)
这篇文章讲述了如何使用OpenCV库进行图像处理,包括从图像中提取最外部轮廓,通过`findContours`函数以`RETR_EXTERNAL`和`CHAIN_APPROX_SIMPLE`模式简化轮廓,并计算轮廓的外接矩形。此外,还介绍了如何利用`pointPolygonTest`来判断一个点是否位于轮廓内部以及获取其距离。
717

被折叠的 条评论
为什么被折叠?



