简体   繁体   English

cv2.error: OpenCV(4.0.0) 错误: (-215:Assertion failed) dst.data == (uchar*)dst_ptr in function 'cvShowImage'

[英]cv2.error: OpenCV(4.0.0) error: (-215:Assertion failed) dst.data == (uchar*)dst_ptr in function 'cvShowImage'

import numpy as np
import cv2

# first_method
# img = cv2.imread('sample.jpg')
# second_method
# img = np.zeros((1000, 1000, 3), np.int8) 

while True:
    cv2.imshow('sample', img)
    if cv2.waitKey(20) & 0xFF == 27:
        break
cv2.destroyAllWindows()

In the above code I'm trying to display the image using imshow() function of opencv.在上面的代码中,我试图使用 opencv 的 imshow() 函数显示图像。 When I try to use the first method, ie crating an array from a sample image the code work perfectly, but when I create my own array I get the following error-当我尝试使用第一种方法时,即从示例图像创建数组时,代码运行良好,但是当我创建自己的数组时,出现以下错误 -

PS C:\Users\tanma\Dropbox\Coding\python\AI> python .\test_1.py
Traceback (most recent call last):
  File ".\test_1.py", line 16, in <module>
    cv2.imshow('sample', img)
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window_w32.cpp:1230: error: (-215:Assertion failed) dst.data == (uchar*)dst_ptr in function 'cvShowImage'

I had a similar problem using OpenCV 4.0.0.我在使用 OpenCV 4.0.0 时遇到了类似的问题。 According to this , the bug is fixed in 4.0.1, so you can just update the opencv-python package.根据this ,该错误在4.0.1中已修复,因此您只需更新opencv-python包即可。

My image was of type floating-point, but according to OpenCV Documentation it is ok to show such images:我的图像是浮点类型,但根据OpenCV 文档可以显示这样的图像:

  • If the image is 8-bit unsigned, it is displayed as is.如果图像是 8 位无符号,则按原样显示。
  • If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255*256] is mapped to [0,255].如果图像是 16 位无符号或 32 位整数,则将像素除以 256。即值范围 [0,255*256] 映射到 [0,255]。
  • If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].如果图像是 32 位浮点数,则像素值乘以 255。即值范围 [0,1] 映射到 [0,255]。

Your own array generates an error because the data type 'int8' is incorrect and needs to be changed to 'uint8', ie an 8-bit unsigned integer.您自己的数组会生成错误,因为数据类型“int8”不正确,需要更改为“uint8”,即 8 位无符号整数。 This is because colors are represented by integers 0 - 255, and using a signed integer would only allow for positive integers up until 127.这是因为颜色由整数 0 - 255 表示,并且使用有符号整数将只允许 127 之前的正整数。

暂无
暂无

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

相关问题 OpenNI 和 OpenCV:cv2.imshow() 崩溃并出现错误:(-215:Assertion failed) dst.data == (uchar*)dst_ptr in function &#39;cvShowImage&#39; - OpenNI and OpenCV: cv2.imshow() crashes with error: (-215:Assertion failed) dst.data == (uchar*)dst_ptr in function 'cvShowImage' cv2.error: OpenCV(4.5.2).error: (-215:Assertion failed)._src:empty() in function 'cv::cvtColor' - cv2.error: OpenCV(4.5.2) .error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' cv2.error (-215:Assertion failed) reader.ptr != function cvDrawContours 中的 NULL - cv2.error (-215:Assertion failed) reader.ptr != NULL in function cvDrawContours cv2.error: OpenCV(4.5.2) resize.cpp:4051: error: (-215:Assertion failed).ssize:empty() in function 'cv::resize' - cv2.error: OpenCV(4.5.2) resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV(4.2.0),imwrite() 到子文件夹会破坏模块; cv2.error: (-215:Assertion failed).ssize:empty() in function 'cv::resize'`' - OpenCV(4.2.0),imwrite() to a subfolder breaks the module; cv2.error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'`' 如何在 pycharm 中修复此错误? cv2.error: OpenCV(3.4.2) 错误: (-215:Assertion failed) - How to fix this error in pycharm? cv2.error: OpenCV(3.4.2) error: (-215:Assertion failed) cv2.error:(-215:Assertion failed) !_src.empty() in function &#39;cv::cvtColor&#39; - cv2.error:(-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function &#39;cv::resize&#39; - small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' cv2.error: OpenCV(4.5.5) D:\a\opencv-python\imgproc\src\color.cpp:182: 错误: (-215:Assertion failed) !_src.empty() in function &#39;cv:: cvt颜色&#39; - cv2.error: OpenCV(4.5.5) D:\a\opencv-python\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' cv2.error: OpenCV(4.5.2) C:\\Users\\ ... \\modules\\imgproc\\src\\resize.cpp:3929: error: (-215:Assertion failed) func != 0 in function &#39;cv::hal: :调整大小&#39; - cv2.error: OpenCV(4.5.2) C:\Users\ … \modules\imgproc\src\resize.cpp:3929: error: (-215:Assertion failed) func != 0 in function 'cv::hal::resize'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM