我正在编写一个简单的程序来从相机中获取图像,但出现了一个奇怪的错误:
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)请帮帮忙
发布于 2020-12-29 15:44:56
正如Roland在评论中提到的那样
您应该提供要打开的图像的路径
import cv2
imageArray = cv2.imread('path/to/image.jpg')
cv2.imshow("",imageArray)发布于 2020-12-29 16:26:50
如果你想从相机中读取数据,imread是错误的步骤。它的目的是读取图片文件。
改用OpenCV的VideoCapture。
发布于 2020-12-29 19:21:52
当你在键盘上按下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()https://stackoverflow.com/questions/65488723
复制相似问题