Debug_is_block_type_valid(header->_block_use)



Debug Assertion Failed OpenCv is_block_type_valid(header->_block_use)

I am new to Programming using Visual Studio and openCv. I wrote a simple program to display the red channel of an image, but every time i run the code it throws "DEBUG ASSERTION FAILED" error.

#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>

#include <iostream>

using namespace std;
using namespace cv;

int main() {
    Mat image;
    image = imread("C:/Users/siddartha/Pictures/sample.jpg");
    if (!image.data) {
        cout << "Cannot load image";
        return -1;
    }
    else {
        if (image.channels() >= 3) {
            vector<Mat> rgb;
            split(image, rgb);
            namedWindow("r");
            imshow("r", rgb[0]);

        }
    }
    while (1);
    return 0;
}

Error:

Debug Assertion Failed!

Program: ...sual Studio 2015\Projects\sampleOpenCV\Debug\sampleOpenCV.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 892

Expression: is_block_type_valid(header->_block_use)

Error Window

share | improve this question
 
 

2 Answers 2

up vote 4 down vote accepted

Are you absolutely sure that the image has been loaded correctly?

I would think that it hasn't been loaded correctly and because of that the vectorrgb is empty and, in turn, the element rgb[0] doesn't exist which triggers the exception ...

A couple of things I noted:

  1. Use slashes (/) for include-statements not backslashes (\), i.e.

    #include <opencv2\core.hpp> // Bad!
    #include <opencv2/core.hpp> // Good!
    
  2. In your check

    if (!image.data) { ... } 
    

    do not assume that image.data is set to NULL ornullptr for empty images. Instead check

    if (!image.empty()) { ... }
    
  3. Make sure that calls to cv::imshow(...) are followed by a call tocv::waitKey( /* delay in ms or 0 to wait for user input */ ), cf. the note in theOpenCV reference.

  4. while (1); -- is that intentional? What you want is probably cv::waitKey( 0 ) (see 3.).

UPDATE:

  1. Make sure the vector rgb has been initialized to the number of channels, i.e.

    vector<Mat> rgb(image.channels());
    split(image, rgb);
    // ...
    

UPDATE 2:

Can you tell me what exactly the error meant ?

Three things:

  1. The default constructor of std::vector<T> creates an empty vector.
  2. Apparently, cv::split() expects the caller, i.e. you, to allocate data for the output. If you fail to do so, it's likely provoke asegmentation fault.
  3. For debug builds some compilers add padding or safety memory around objects in memory which is never to be touched. If this padding memory is altered at runtime, the program "knows" that something bad happened and throws an exception like the one you saw.
share | improve this answer
 
 
I did all the corrections you stated. but now it shows DEBUG Assertion Failure when i press a key in the end to exit. –  sidd607 Jan 14 '16 at 13:30
 
Updated my answer. –  nils Jan 14 '16 at 14:01
 
updating the rgb worked for me. Can you tell me what exactly the error meant ? –  sidd607 Jan 14 '16 at 15:09
 
Updated my answer again. –  nils Jan 15 '16 at 9:05

it is compiling just fine for me. I am on visual-studio-2013.

here you have a case similar to yours, maybe it will help: debug-assertion-failed

share | improve this answer
 
 
thanks dude, how could i forget about it? –  Dominik Jan 13 '16 at 8:35
 
true, it was wrong hypothesis then : ) –  Dominik Jan 13 '16 at 8:54
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值