python - 读取和扭曲图像(-215:断言失败)size.width>0 && size.height>0 in function 'cv::imshow'
问题描述
import cv2
img =cv2.imread('OIP.jpg')
cv2.imshow("oip" , img)
cv2.waitkey(0)
cv2.imwrite('OIP.png', img)
cv2.destroyAllWindows()
这是错误
runfile('C:/Users/user/reading and writing an image.py', wdir='C:/Users/user') Traceback (most recent call last): File "C:\Users\user\reading and writing an image.py", line 13, in <module> cv2.imshow("oip" , img) error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
解决方案
你能说你的img
价值不为空吗?(此错误表明您的文件不存在)
例如:
import numpy as np
print(len(np.shape(img))) #should be equals or greater 2
此致
推荐阅读
- node.js - 状态码:Heroku 上托管的 React 前端中不允许出现 405
- javascript - StaticInjectorError(AppModule)[NgForOf -> TemplateRef]
- python - 将接收到的数据传递给python中的“输入”函数
- c# - 如何在 MYSQL 数据阅读器中转换 3 倍 int?
- sql - 编译 SQLCLR 函数期间出现 NullReferenceException
- javascript - 是否可以将 nglAccordionSection 手风琴的标签作为组件或 html 元素而不仅仅是文本?
- spring-boot - 无法从命令行配置数据源
- image - 给定表示图像的 FLATTENED 数组中像素的 HEIGHT 、 WIDTH 和索引,获取像素的 X 和 Y 位置
- java - 抛出异常后如何处理 SFTP 入站适配器轮询中的剩余文件?
- html - 是否可以为 Pug 中的每个标题生成锚点?