error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow‘(已解决)

错误的原因是cv.imshow这个函数

搜这个问题的时候发现很多博客在胡扯,这个函数的第一个参数根本不是什么地址

cv2.imshow('显示窗口名称',图像数组)
def imshow(winname, mat): # real signature unknown; restored from __doc__
"""
    .   -   If the image is 8-bit unsigned, it is displayed as is.
    .   -   If the image is 16-bit unsigned, 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 or 64-bit floating-point, the pixel values are multiplied by 255. That is, the
    .       value range [0,1] is mapped to [0,255].
    .   -   32-bit integer images are not processed anymore due to ambiguouty of required transform.
"""

解决方案:

其中图像数组是numpy类型,如果是RGB三通道类型的,数组大小为:图像长*图像宽*3

 若出现报错,先检查是不是图像数组有问题,改成规定格式就能成功解决

注:

cv.show()函数测试

import cv2
img=cv2.imread('2007_000876.jpg')
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

参考资料:

下面这个错误原因是,变量名不能重复使用

python - error: (-215:Assertion failed) bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32) in function 'FillBitmapInfo - Stack Overflow

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
这个错误是由于在使用cv2.imshow函数时,传入的图像尺寸出现了问题。具体地说,图像的宽度和高度需要大于0才能正确显示。根据引用、和中的报错信息,你可以查看你的代码中是否正确读取了图片,并且确认图片的尺寸是否正确。如果图片的尺寸为0,那么你需要检查图片文件是否存在、路径是否正确,或者尝试使用其他图片进行测试。如果图片的尺寸不为0,那么你可能需要检查其他代码部分,如图像处理过程中是否存在异常,或者其他函数的调用是否正确。请仔细检查你的代码,并确保所有输入参数的正确性,以解决这个错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [出现 error: (-215:Assertion failed) size.width0 && size.height0 in functioncv::imshow‘ 的...](https://blog.csdn.net/weixin_47872288/article/details/126736861)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [opencv bug 处理](https://download.csdn.net/download/rechard_han/10562169)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [error: (-215:Assertion failed) size.width0 && size.height0 in functioncv::imshow](https://blog.csdn.net/qq_48740719/article/details/130046421)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坠金

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值