我想创建一个程序来保存从网络摄像头拍摄的 .jpg 图像(帧)。 我的程序现在做的是,打开一个网络摄像头,只拍摄一帧,然后一切都停止了。
我想要的不仅仅是一帧 我的错误代码是这个:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
count = 0
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imwrite("frame%d.jpg" % ret, frame) # save frame as JPEG file
count +=1
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(10):
break
最佳答案
实际上听起来你总是用相同的名字保存你的图像 因为您在 imwrite 方法中连接 ret 而不是 count
试试这个:
name = "frame%d.jpg"%count
cv2.imwrite(name, frame) # save frame as JPEG file
关于python - 将视频保存为帧 OpenCV{PY},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27378662/