以下のコードから、重心を小さな円でマークし、船体を黄色の線でマークして、最大の等高線を描くことができます。凸性欠陥をどのように描画しますか? circle() 関数または drawContours() 関数を使用する必要がありますか?
Mat bw;
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( bw, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
int s = getBiggestContour(contours);
Mat drawing = Mat::zeros( src.size(), CV_8UC3 ); //UC1
Point2f mc = getCentroidPoint(contours[s]);
drawContours( drawing, contours, s, Scalar(255,255,255), -1, 8, hierarchy, 0, Point() );
circle( drawing, mc, 4, Scalar(0,0,255), 1, 8, 0 );
vector<vector<Point> >hull( contours[s].size() );
convexHull( Mat(contours[s]), hull[s], false );
drawContours( drawing, hull, s, Scalar(0,255,255), 1, 8, vector<Vec4i>(), 0, Point() );
上記のコードは機能しますが、使用する輪郭は 1 つだけで、これが最大の輪郭であるため、ハルに vector> を使用するのは多すぎると思います。それをどのように単純化しますか?
以下のコードは、別のスタックオーバーフローの質問からのものですが、Mat 画像に凸性欠陥を描画する際に欠陥変数を使用する方法を示していません。これはどのように達成できますか?
vector<vector<int> > hullsI(contours.size());
vector<vector<Point> > hullsP(contours.size());
vector<vector<Vec4i> > defects(contours.size());
for(int i = 0; i <contours.size(); ++i){
//find the hulls
convexHull(contours[i], hullsI[i], false, false);
convexHull(contours[i], hullsP[i], false, true);
//find the defects
if (contours[i].size() >3 ){
convexityDefects(contours[i], hullsI[i], defects[i]);
}
}
IplImage を使用したくありません。私はマットの方が好きです。