OpenCV で findCountours() を使用しているときにこれに遭遇しました。 デバッグ アサーションに失敗し ました
void HandTrack::ProcessFrame(...){
...
//Convert the colorImage into grayImage
Mat GrayImage;
cvtColor(ColorImages, GrayImage, CV_BGR2GRAY);
//Convert grayImage into binaryImage
Mat BinaryImage(GrayImage.rows, GrayImage.cols, CV_8UC1);
threshold(GrayImage, BinaryImage, 254, 255, CV_THRESH_BINARY);
bitwise_not(BinaryImage, BinaryImage);
//Get the contours from binaryImage
vector<vector<Point>> hand_contours;
findContours(BinaryImage, hand_contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
BinaryImage.release();
//Draw the contours
Mat OutlineImage(GrayImage.rows, GrayImage.cols, CV_8UC1);
rectangle(OutlineImage, Point(0, 0), Point(BinaryImage.cols, BinaryImage.rows), Scalar(255, 255, 255),-1,8);
if (hand_contours.size() > 0) {
drawContours(OutlineImage, hand_contours, -1, (0, 0, 0), 1);
}
waitkey(1);
}
以下は私が試したことです:
imshow("img",BinaryImage);
最後に追加して、何も変わらない;この行にコメントしてください↓、すべてうまくいきます
findContours(BinaryImage, hand_contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
コードをステップ実行します。
waitkey(1); }
hand_contours.~vector();
waitkey(1) の前に追加(関数の破壊); Debug Assertion Failed はどこにいても表示されます。
最後に、ローカル変数「hand_contours」をグローバル変数に変更して解決しました。 しかし、なぜそれが解決したのか、私はまだ疑問に思っています。読んでくれてありがとう:)