cv2.error:OpenCV(4.0.0)错误:(-215:断言失败)dst.data ==(uchar *)dst_ptr在函数'cvShowImage'中 [英] cv2.error: OpenCV(4.0.0) error: (-215:Assertion failed) dst.data == (uchar*)dst_ptr in function 'cvShowImage'

查看:2775
本文介绍了cv2.error:OpenCV(4.0.0)错误:(-215:断言失败)dst.data ==(uchar *)dst_ptr在函数'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()

在上面的代码中,我试图使用opencv的imshow()函数显示图像.当我尝试使用第一种方法时,即从示例图像中创建数组时,代码可以正常工作,但是当我创建自己的数组时,出现以下错误-

In the above code I'm trying to display the image using imshow() function of opencv. When I try to use the first method, i.e 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'

推荐答案

我在使用OpenCV 4.0.0时遇到了类似的问题.根据,此错误已在4.0.1中修复,因此您可以只需更新opencv-python软件包即可.

I had a similar problem using OpenCV 4.0.0. According to this, the bug is fixed in 4.0.1, so you can just update the opencv-python package.

我的图片是浮点类型,但根据 OpenCV文档可以显示此类图像:

My image was of type floating-point, but according to OpenCV Documentation it is ok to show such images:

  • 如果图像是8位无符号的,则按原样显示.
  • 如果图像是16位无符号或32位整数,则像素除以256. 即,值范围[0,255 * 256]被映射到[0,255].
  • 如果图像为32位浮点,则像素值将乘以255.即,值范围[0,1]映射为[0,255].
  • If the image is 8-bit unsigned, it is displayed as is.
  • 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].
  • 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].

这篇关于cv2.error:OpenCV(4.0.0)错误:(-215:断言失败)dst.data ==(uchar *)dst_ptr在函数'cvShowImage'中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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