简体   繁体   English

Debug Assertion失败OpenCv 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. 我是使用Visual Studio和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. 我写了一个简单的程序来显示图像的红色通道,但每次运行代码时都会抛出“DEBUG ASSERTION FAILED”错误。

#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)

错误窗口

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 vector rgb is empty and, in turn, the element rgb[0] doesn't exist which triggers the exception ... 我认为它没有正确加载,因为向量rgb是空的,反过来,元素rgb[0]不存在,触发异常......

A couple of things I noted: 我注意到的一些事情:

  1. Use slashes ( / ) for include-statements not backslashes ( \\ ), ie 使用斜杠( / )表示包含语句而不是反斜杠( \\ ),即

     #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 or nullptr for empty images. 不要假设image.data设置为NULLnullptr为空图像。 Instead check 相反检查

     if (!image.empty()) { ... } 
  3. Make sure that calls to cv::imshow(...) are followed by a call to cv::waitKey( /* delay in ms or 0 to wait for user input */ ) , cf. 确保对cv::imshow(...)的调用之后是对cv::waitKey( /* delay in ms or 0 to wait for user input */ )的调用cv::waitKey( /* delay in ms or 0 to wait for user input */ ) ,参见 the note in the OpenCV reference . OpenCV参考中的注释。

  4. while (1); -- is that intentional? - 那是故意的吗? What you want is probably cv::waitKey( 0 ) (see 3.). 你想要的可能是cv::waitKey( 0 ) (见3.)。

UPDATE: 更新:

  1. Make sure the vector rgb has been initialized to the number of channels, ie 确保向量rgb已初始化为通道数,即

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

UPDATE 2: 更新2:

Can you tell me what exactly the error meant ? 你能告诉我这个错误究竟是什么意思吗?

Three things: 三件事:

  1. The default constructor of std::vector<T> creates an empty vector. std::vector<T>的默认构造函数创建一个向量。
  2. Apparently, cv::split() expects the caller, ie you , to allocate data for the output. 显然, cv::split()期望调用者(即您)为输出分配数据。 If you fail to do so, it's likely provoke a segmentation 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. 如果在运行时更改了这个填充内存,程序会“知道”发生了一些不好的事情并引发了一个异常,就像你看到的那样。

it is compiling just fine for me. 它正在编译对我来说很好。 I am on visual-studio-2013. 我在视觉工作室 - 2013年。

here you have a case similar to yours, maybe it will help: debug-assertion-failed 在这里你有一个类似于你的案例,也许它会有所帮助: debug-assertion-failed

暂无
暂无

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

相关问题 为什么我解决了“调试断言失败的OpenCv is_block_type_valid(header-&gt; _ block_use)” - WHY I solved “Debug Assertion Failed OpenCv is_block_type_valid(header->_block_use)” 图片不显示,关闭时出现错误 --&gt; Debug Assertion Failed! 表达式:is_block_type_valid(header-&gt;_block_use) - the picture is not displayed and an error occurs when turning off --> Debug Assertion Failed! Expression: is_block_type_valid(header->_block_use) 调试断言失败! 表达式:is_block_type_valid(header-&gt; _ block_use)。 对象不会初始化和推送错误 - Debug Assertion Failed! Expression: is_block_type_valid(header->_block_use). Object wont init and Push error 为什么我会得到 _CrtIsValidHeapPointer(block) 和/或 is_block_type_valid(header-&gt;_block_use) 断言? - Why do I get _CrtIsValidHeapPointer(block) and/or is_block_type_valid(header->_block_use) assertions? 调试断言失败:_BLOCK_TYPE_IS_VALID - Debug assertion failed: _BLOCK_TYPE_IS_VALID 调试声明失败(_BLOCK_TYPE_IS_VALID)…此解决方案有效吗? - Debug Assertion Failed (_BLOCK_TYPE_IS_VALID)… Is this solution valid? 调试断言失败_BLOCK_TYPE_IS_VALID(pHead-&gt; nBlockUse) - Debug Assertion Failed _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 错误 调试断言失败。 BLOCK_TYPE_IS_VALID - Error Debug Assertion Failed. BLOCK_TYPE_IS_VALID 调试断言失败... _BLOCK_TYPE_IS_VALID(pHead-&gt; nBlockUse) - Debug Assertion Failed … _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 此代码有什么问题? 为什么显示:调试断言失败! _BLOCK_TYPE_IS_VALID(pHead-&gt; nBlockUse)? - What is the trouble with this code? Why is it showing: Debug assertion failed! _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM