1

次のコードを見てください

宣言

vector<vector<Point>> *contours;
vector<vector<Point>> *contoursPoly;

contours = new vector<vector<Point>>();
contoursPoly = new vector<vector<Point>>();

実装

//Find contours
findContours(*canny,*contours,*heirarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0));

//Draw contours
//drawContours(*current,*contours,-1,Scalar(0,0,255),2);

for(int i=0;i<contours->size();i++)
{
  cv::approxPolyDP(Mat(contours[i]),contoursPoly[i], 3, true);
}

このコードを実行するとすぐにエラーが発生します

A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in Automated  System.exe
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in Automated System.exe

このエラーは、コードのこのコード部分から発生しています

cv::approxPolyDP(Mat(contours[i]),contoursPoly[i], 3, true);

なぜ私はこれを手に入れたのですか?

4

1 に答える 1

1

contoursPolyベクトルへのポインタです。

contoursPoly[i]ベクトルへのポインタをベクトルの配列として扱い、ith を取得します。

(*contoursPoly)[i]最初にポインターを逆参照するが必要です。そしておそらく同じです(*contours)[i]

さらに、ベクトルへのポインターを使用する理由がない可能性もあります。

交換:

vector<vector<Point>> *contours;
vector<vector<Point>> *contoursPoly;

contours = new vector<vector<Point>>();
contoursPoly = new vector<vector<Point>>();

vector<vector<Point>> contours;
vector<vector<Point>> contoursPoly;

*次に、以下から間接参照 s を削除します。

findContours(*canny,*contours,*heirarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0));

このような:

findContours(canny,contours,*heirarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0));

std::vector<std::vector<Point>>*関数の引数を引数に変更しstd::vector<std::vector<Point>>&ます。->そのような変数の使用を の使用に置き換え.、逆参照を削除します。

ヒープ ベースの割り当て (つまり、フリー ストア) は、C++ でときどき行う必要があるものです。不必要にしないでください。

于 2013-07-13T15:40:26.227 に答える