我试着做基本的OpenCV操作。代码在PyCharm中运行良好,没有错误。得到了一个输出窗口。但是,当在VS代码中时,我得到了以下错误。
PS E:\Personal Project\OpenCV> python -u "e:\Personal Project\OpenCV\Codes\Start.py"
[ WARN:0@0.029] global loadsave.cpp:244 cv::findDecoder imread_('Capture.PNG'): can't open/read file: check file path/integrity
Traceback (most recent call last):
File "e:\Personal Project\OpenCV\Codes\Start.py", line 8, in <module>
cv2.imshow('Image', img)
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:971: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
沿着这是代码
import cv2
# Read the image
img = cv2.imread('Capture.PNG')
# Display the image
cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
我的Python版本3.10.7,Python3版本3.9.13我的Pip,pip3版本22.3.1。我的VSCode和PyCharm解释器都使用python 3.10.7
1条答案
按热度按时间rqqzpn5f1#
错误在
img = cv2.imread('Capture.PNG')
行中看起来目录“Capture.png”不存在...所以可能需要重新检查您的目录,确保图像保存正确