简体   繁体   English

某些Pixal值上的OpenCV错误断言失败

[英]OpenCV Error Assertion failed on some Pixal Values

I loaded an Image to a Mat: 我把图像加载到垫子上:

Mat Mask = cvLoadImage(filename);

Its an 3744 X 5616 RGB Image. 它是一个3744 X 5616 RGB图像。 On the next Step i convert it to an Grayscale. 在下一步我将其转换为灰度。

cvtColor(Mask,Mask,CV_BGR2GRAY);

after this i normalize it to use the full Grayscale later: 在此之后我将其标准化以便稍后使用完整的灰度:

normalize(Mask,Mask,0,255,NORM_MINMAX,CV_8U);

Now i need the specific Grayscale values and getting an Error on some Values: 现在我需要特定的灰度值并在某些值上获得错误:

for(int i=0;i<(Picture.rows);i++)
{
    for(int j=0;j<(Picture.cols);j++)
    {
Vec3b  masked = Mask.at<Vec3b>(i,j);
//some stuff
}
}

I'm getting the Following Error on some Pixels: 我在某些像素上遇到以下错误:

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in unknown function, file c:\opencv\build\include\opencv2\core\mat.hpp, line 537

Anyone can tell me what i did wrong? 谁能告诉我我做错了什么? It's strange that it appears only on some Pixel Values 奇怪的是它只出现在某些Pixel Values上

Edit: Additional Information: If I load my Mask as Grayscale everything works fine. 编辑:附加信息:如果我将我的面具加载为灰度,一切正常。 But when I use cvtColor() or Mat Mask = imread(filename,CV_LOAD_IMAGE_GRAYSCALE); 但是当我使用cvtColor()或Mat Mask = imread(filename,CV_LOAD_IMAGE_GRAYSCALE)时; on the image the error appears. 在图像上出现错误。 Very Strange... 很奇怪...

I think your problem is you are accessing a binary image with .at<Vec3b>(i,j) . 我认为您的问题是您正在使用.at<Vec3b>(i,j)访问二进制图像。 Instead you want to access each pixel with .at<uchar>(i,j) . 相反,您希望使用.at<uchar>(i,j)访问每个像素。 cvtColor(Mask,Mask,CV_BGR2GRAY); changes the 3 channel BGR image to a one channel grayscale image. 将3通道BGR图像更改为单通道灰度图像。 .at<Vec3b>(i,j) is trying to access a 3 channel image which will eventually go past the end of the image array in memory causing problems or tripping those assertions. .at<Vec3b>(i,j)正在尝试访问3通道图像,该图像最终将超过内存中图像数组的末尾,从而导致问题或使这些断言失效。

The inner part of your for loop should look like this: for循环的内部部分应如下所示:

unsigned char masked = Mask.at<uchar>(i,j);

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

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