簡體   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