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;
}
原图: 结果图: