【发布时间】:2016-07-19 14:37:17
【问题描述】:
我在 OpenCV 中使用 findCountours() 时遇到过这种情况, Debug Assertion Failed 我有很多谷歌,但没有任何帮助,以下是我的代码的一部分。
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); } 在waitkey(1)之前添加
hand_contours.~vector();(destruct fuction); Debug Assertion Failed 显示在哪里;
最后,我通过将局部变量“hand_contours”更改为全局变量来解决它。 但我仍然想知道为什么它解决了。感谢阅读:)
【问题讨论】:
-
问题出在您的配置中。请务必在调试模式下链接到调试 OpenCV 库,并在发布时发布库。还要确保使用使用与您的项目相同的编译器编译的 OpenCV。现在你还没有解决问题,它只是被隐藏了
-
你好三木,谢谢你的回答,我之前也找到了一些类似的答案。我不擅长配置,但我会尝试检查一下,谢谢。
标签: c++ opencv vector point opencv-contour