在图像处理和分析中,通常会遇到求物体的凸包或某类型形状的凸包,以下函数可以实现该功能:
- void get_hull(cv::Mat& src,int thresh)
- {
- Mat src_copy = src.clone();
- Mat threshold_output;
- vector<vector<Point> > contours;
- vector<Vec4i> hierarchy;
-
- threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
- 查找轮廓
- findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
- 找到每个轮廓的凸包对象
- vector<vector<Point> >hull( contours.size() );
- for( int i = 0; i < contours.size(); i++ )
-