繁体   English   中英

为什么我解决了“调试断言失败的OpenCv is_block_type_valid(header-> _ block_use)”

[英]WHY I solved “Debug Assertion Failed OpenCv is_block_type_valid(header->_block_use)”

当我在OpenCV中使用findCountours()时,我遇到了这个问题, 调试断言失败我有很多Google信息,但没有任何帮助,以下是我代码的一部分。

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);
}

以下是我尝试的方法:

  1. 添加imshow("img",BinaryImage); 最后,什么都没有改变;

  2. 评论这行↓,一切顺利

    findContours(BinaryImage, hand_contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

  3. 逐步执行代码,一切正常,直到

    waitkey(1); }

  4. 添加hand_contours.~vector(); (破坏功能)在waitkey(1)之前; 无论位于何处,Debug Assertion Failed都会显示;

最后,我通过将局部变量“ hand_contours”更改为全局变量来解决了该问题。 但是我仍然想知道为什么它解决了。 感谢您的阅读:)

忽略它,调试中的图像

您的问题在这里的某处:

//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;

您将BinaryImage创建为CV_8UC1,这很好,但是我有种感觉,您的GrayImage不会总是“ ...一个8位单通道图像”。 根据文档要求 一路上的某个地方可能无法正确截断。

您的GrayImage是从彩色图像派生的,可能偶尔会有一些空白通道。 检查并确保dst和src Mat的格式正确(这是断言失败源的99.9%)。

至于如何通过改变全球性来解决这个问题? 在没有看到其余代码的情况下,实际上是没有办法说出来的。 我最好的猜测是,在某种程度上,它导致您的某些功能将MAT的内容更改为您想要的格式,然后再到达上面显示的功能。 但是,如果没有看到,实际上是没有办法说出来的。

但是,故事的实质是,只要您可以检查src和dst的格式是否正确,就可以避免大多数断言失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM