std::vector<cv::Point> GetVertex(cv::Mat src)
{
Mat img;
src.copyTo(img);
threshold(img, img, 200, 255, CV_THRESH_BINARY);
std::vector<std::vector<cv::Point>> point;
vector<Vec4i>g_vHierarchy1;//层次结构信息
findContours(img, point, g_vHierarchy1, RETR_CCOMP, CHAIN_APPROX_NONE, Point(0, 0));
std::vector<cv::Point> vertex_point;
cv::Mat paint1(img.size(), CV_8UC3, cv::Scalar(0, 0, 0));
auto i = point.begin();
approxPolyDP(*i, vertex_point, 7, 1);
for (auto a : vertex_point)
{
cv::circle(paint1, a, 2, cv::Scalar(0, 0, 255));
}
cv::imshow("roi_approx", paint1);
waitKey(0);
return vertex_point;
}
原图:
结果图:![]()
本文介绍了一种使用OpenCV库进行图像处理的方法,通过二值化、轮廓查找及近似多边形处理,实现从图像中提取目标轮廓并定位其顶点位置,最后将顶点在新图像上进行可视化展示。

3466

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



