OpenCV:断言失败“函数"cvImageWidgetSetImage"中的dst.data == widget-> original_image-> data.ptr [英] OpenCV: Assertion failed " dst.data == widget->original_image->data.ptr in function 'cvImageWidgetSetImage' "

查看:331
本文介绍了OpenCV:断言失败“函数"cvImageWidgetSetImage"中的dst.data == widget-> original_image-> data.ptr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重要提示: :我已解决此问题. 最后的解决方案.

我要达到什么目的? 使用OpenCV cv :: imshow 方法显示图像. ( imshow文档)

What do I try to achieve? Display an image with OpenCV cv::imshow method. (imshow Documentation)

创建的3x3矩阵图像如下所示:

The image which is a 3x3 matrix is created like such:

Mat mask(3, 3, CV_32F, new float[9]{0, 1, 0, 1, -4, 1, 0, 1, 0});

要显示我调用的图像imshow("mask", mask);

我怎么了? 就像我在标题中提到的那样,尝试显示图像时会引发异常.完整的错误消息:

What is my problem? Like I mentioned in the title there is an exception thrown while trying to display the image. Complete Error Message:

terminate called after throwing an instance of 'cv::Exception' what():  
OpenCV(4.0.0-pre) /home/mrlab/Libraries/opencv_source/modules/highgui
/src/window_gtk.cpp:146: error: (-215:Assertion failed) 
dst.data == widget->original_image->data.ptr in function 'cvImageWidgetSetImage'

链接到 window_gtk. a>

Link to window_gtk.cpp

我已经尝试了什么?

  1. 在互联网上查找错误.也许其他人已经遇到了同样的问题. 不.没有
  2. 将矩阵更改为仅包含正浮点值(从0到1),以防输入出现问题.初始化:Mat mask(3, 3, CV_32F, new float[9]{0, 1, 0, 1, 0, 1, 0, 1, 0}); 相同错误
  3. 在其他代码中进行更改的情况下,请在不同位置调用这两个方法. 相同的错误
  4. 编写小型OpenCV程序以仅运行这两行. 相同的错误
  5. 上述想法的各种组合. 相同的错误
  6. 显示我从内存中读取的其他图像,而不是自己创建. 工作得很好
  7. 通过imwrite("mask.png", mask)保存图像看起来像 .我知道的很小.我将值缩放到0到25​​5的范围内,因为png需要什么. 工作正常
  1. Looking for the error on the internet. Maybe someone else already encountered the same problem. nope. nothing
  2. Changed the matrix to only contain positive floating point values (0 to 1) in case it has problems with negative input. Initialization: Mat mask(3, 3, CV_32F, new float[9]{0, 1, 0, 1, 0, 1, 0, 1, 0}); same error
  3. Calling the two methods in different locations in case there are changes made during my other code. same error
  4. Writing small OpenCV program to just run these two lines. same error
  5. Various combinations of the above mentioned ideas. same error
  6. Displaying other images I read from memory instead of creating them myself. worked perfectly fine
  7. Saving the image via imwrite("mask.png", mask) Looks like this. Pretty small I know. I scaled the values to be in range of 0 to 255 since that what png needs. works perfectly fine

围绕我已损坏的行填写代码:

void high_pass(){

  Mat src_f;
  // Fourier transform src_bw
  src_f = fourier(src_bw);

  // Create Laplace High Pass Kernel
  Mat mask(3, 3, CV_32F, new float[9]{0, 1, 0, 1, -4, 1, 0, 1, 0});
  // In case of using fp values (0 to 1) initialize like this:
  // Mat mask(3, 3, CV_32F, new float[9]{0, 1, 0, 1, 0, 1, 0, 1, 0});
  imshow("mask", mask);

  // Fourier transform kernel
  Mat mask_f = fourier_kernel(mask, src_f.size());

  Mat hp_filtered;
  // Apply filter
  mulSpectrums(src_f, mask_f, hp_filtered, DFT_ROWS);

  // Transform it back
  dst = fourier_inv(hp_filtered);

  // Swap quadrants after applying filter
  dst = swap_quadrants(dst);

  // Show result
  //imshow(WINDOW_NAME + "high pass", dst);
}

仅供参考::最后一行引发了相同的异常,这就是为什么将其注释掉了.我用遮罩"问这个问题,因为它更容易.

FYI: The last line threw the same exception which is why it is commented out. I ask the question with "mask" because it is easier.

写完问题后,我有了另一个主意.

After writing the question I had another idea.

解决方案:我将CV_32F类型的矩阵转换为CV_8U矩阵,并将所有值缩放到0到25​​5的范围内.这解决了问题.

Solution: I converted the CV_32F type matrix to a CV_8U matrix and scaled all values to be in range of 0 to 255. This solved the problem.

这是我应该首先想到的.由于某种原因,我花了一个小时才意识到.万一有人遇到相同的错误或思维障碍,我还是在这里发布.

This is something I should have thought of first. For some reason it took me one hour to realize. Just in case someone else is encountering the same error or mental block I still post this here.

推荐答案

解决方案:我将CV_32F类型矩阵转换为CV_8U矩阵,并将所有值缩放为0到255之间的范围.解决了问题.

Solution: I converted the CV_32F type matrix to a CV_8U matrix and scaled all values to be in range of 0 to 255. This solved the problem.

如Nikolaj Fogh所述,还可以恢复到OpenCV版本3.4.3.我自己没有测试.

As stated by Nikolaj Fogh it is also possible to revert to OpenCV Version 3.4.3. I did not test it myself.

这篇关于OpenCV:断言失败“函数"cvImageWidgetSetImage"中的dst.data == widget-> original_image-> data.ptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆