我正在尝试在 Jupyter notebook 中运行代码,但它显示错误SyntaxError: 'break' outside loopimport cv2import syscpt=0vidStream=cv2.VideoCapture(0)while True: ret,frame=vidStream.read()cv2.imshow("Test Frame", frame) cv2.imwrite(r"E:\Face_Detection_Project\Test_images\0\image%04i.jpg" %cpt,frame)cpt +=1if cv2.waitKey(10)==ord('q'): break
2 回答
尚方宝剑之说
TA贡献1788条经验 获得超4个赞
中断应该在while循环内。要在里面,您需要添加缩进,如下所示:
import cv2
import sys
cpt=0
vidStream=cv2.VideoCapture(0)
while True:
ret,frame=vidStream.read()
cv2.imshow("Test Frame", frame)
cv2.imwrite(r"E:\Face_Detection_Project\Test_images\0\image%04i.jpg" %cpt,frame)
cpt +=1
if cv2.waitKey(10)==ord('q'):
break
添加回答
举报
0/150
提交
取消