[英]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 文档可以显示这样的图像:
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.