我是python的新手,我想每5秒从网络摄像头捕获一次图像。
import cv2 as cv
import time
camera = cv.VideoCapture(0)
name = 1
while(True):
ret, image = camera.read()
cv.imwrite('webcam'+str(name)+'.jpg', image)
time.sleep(5)
name+1
camera.release()
cv.destroyAllWindows()
与我的预期相反,该循环似乎无法正常工作,仅保存了一张图像(webcam1.jpg)。我究竟做错了什么?
您在以下行中出现语法错误:
name+1
这将导致脚本在第一次迭代后停止。
您可能想增加该值:
name += 1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句