I have encounter this when I using findCountours() in OpenCV, Debug Assertion Failed I have google a lot but nothing helped me, following is part of my codes.
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);
}
Belows is what I've try:
Add
imshow("img",BinaryImage);
at last, and nothing change;Comment this line↓, everything goes well
findContours(BinaryImage, hand_contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
Step through the codes, everything is well until the ‘}’ below the
waitkey(1); }
Add
hand_contours.~vector();
(destruct fuction) before waitkey(1); the Debug Assertion Failed show wherever it are;
At last, I solved it by changing the local variable 'hand_contours' into global variable. But I still wondering why it solved. Thanks for read :)