#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("手.png");
if (img.empty())
{
cout << "输入为可空";
return -1;
}
Mat gray, binary;
cvtColor(img, gray, COLOR_BGR2GRAY);
threshold(gray, binary, 105, 0, THRESH_BINARY);
imshow ("", binary);
vector <vector<Point>> contours;
vector<Vec4i> hierachy;
findContours(binary, contours, hierachy, 0, 2, Point());
for (int t = 0; t < contours.size(); t++)
{
vector<Point> hull;
convexHull(contours[t], hull);
for (int i = 0; i < hull.size(); i++)
{
circle(img, hull[i], 4, Scalar(255, 0, 0), 2, 8, 0);
if (i == hull.size() - 1)
{
line(img, hull[i], hull[0], Scalar(255, 0, 255), 2, 8, 0);
break;
}
line(img, hull[i], hull[i + 1], Scalar(255, 0, 255), 2, 8, 0);
}
}
imshow("img", img);
waitKey(0);
return 0;
}
01-20
2590
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)