0

次のコードから Convexity Defects を取得しようとしていますが、未処理の例外が引き続き発生します。私は何を間違っていますか?

vector<Vec4i> defects;
ContourPoly = vector<Point>(contour.size());
approxPolyDP( Mat(contour), ContourPoly,20, false );
convexHull(Mat(ContourPoly), HullPoints, false, true);
// The following line wont work
convexityDefects(Mat(ContourPoly),HullPoints,defects);

HullPoints は型ですが、vector<Point> 例外は次のとおりです。

OpenCV Error: Assertion Failed (ptnum >3) is unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1969

しかし、 vector<Point> defects;またはvector<Vec4i> defects 次の例外が発生します

 OpenCV Error: Assertion Failed (hull.checkVector(1,CV_32S) is unknown function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1971
4

2 に答える 2

0

初めに

vector<vector<Vec4i> > defects;

次のようにする必要があります。

vector<vector<Vec4i> > defects( contour.size() );

また、convexityDefects関数を呼び出す前に、のサイズがHullPoints3 より大きいかどうかを確認します。

于 2013-12-29T20:33:40.940 に答える
0

defectsする必要がありますvector<Vec4i>

ドキュメントから:

各凸性欠陥は、4 要素の整数ベクトル (別名cv::Vec4i)として表され(start_index, end_index, farthest_pt_index, fixpt_depth)ます。ここで、インデックスは、凸性欠陥の開始点、終了点、および最も遠い点の元の輪郭の 0 ベースのインデックスであり、fixpt_depth固定小数点近似 (小数ビットが 8 の場合) です。 ) は、最も遠いコンター ポイントとハルの間の距離です。つまり、深さの浮動小数点値を取得するには、fixpt_depth/256.0

于 2013-04-09T17:29:38.253 に答える