[英]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: 我注意到的一些事情:
Use slashes ( /
) for include-statements not backslashes ( \\
), ie 使用斜杠( /
)表示包含语句而不是反斜杠( \\
),即
#include <opencv2\\core.hpp> // Bad! #include <opencv2/core.hpp> // Good!
In your check 在你的支票
if (!image.data) { ... }
do not assume that image.data
is set to NULL
or nullptr
for empty images. 不要假设image.data
设置为NULL
或nullptr
为空图像。 Instead check 相反检查
if (!image.empty()) { ... }
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参考中的注释。
while (1);
-- is that intentional? - 那是故意的吗? What you want is probably cv::waitKey( 0 )
(see 3.). 你想要的可能是cv::waitKey( 0 )
(见3.)。
UPDATE: 更新:
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: 三件事:
std::vector<T>
creates an empty vector. std::vector<T>
的默认构造函数创建一个空向量。 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 . 如果你没有这样做,它可能会引发分段错误 。 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.