![](/img/trans.png)
[英]Using cv2.imread: “<built-in function imread> returned NULL without setting an error”, as if it can't open the picture or get the data
[英]cv2.imread error:img = cv2.imread(0) SystemError: <built-in function imread> returned NULL without setting an error
我正在制作一个简单的程序来从相机拍摄图像,但发生了一个奇怪的错误:
Traceback (most recent call last):
File "the path was deleted for stackoverflow", line 3, in <module>
cv2.imshow("",img)
TypeError: Expected Ptr<cv::UMat> for argument 'mat'
这是简单的代码:
import cv2
img = cv2.imread(0)
cv2.imshow("",img)
请帮忙
正如罗兰在评论中提到的
您应该提供要打开的图像的路径
import cv2
imageArray = cv2.imread('path/to/image.jpg')
cv2.imshow("",imageArray)
如果您想从相机读取, imread
是错误的程序。 它的目的是读取图片文件。
改用 OpenCV 的VideoCapture
。
当您从键盘按下 c 时,以下代码将拍照,然后它将图像存储在您的当前目录中。 希望这对你有用,和平!
import cv2
cap = cv2.VideoCapture(0)
width = 400
height = 300
num = 0
while True:
ret, frame = cap.read()
frame = cv2.resize (frame, (width, height))
cv2.imshow("frame", frame)
#When you press c then it would capture a picture and write on the same folder
if cv2.waitKey(1) & 0xff == ord('c'):
cv2.imwrite("./Image_"+str(num)+".jpg", frame)
num+=1
if cv2.waitKey(1) & 0xff == ord('q'):
break
cv2.destroyAllWindows()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.