我想捕获图像并存储在我的本地系统后,每隔n秒,我不能设置帧(5),因为我想视频和检测运行完全。目前我的代码是捕获图像时,条件失败。
def create_alert(self):
count = 0
cap = cv2.VideoCapture(0)
while cap.isOpened():
r,f = cap.read()
try:
info = ppe.detection(f)
x,y,w,h,label,conf = info[0]
if label == "lineman_fail":
# engine.say("Warning")
# engine.runAndWait()
ppe.take_screenshot(f,count)
count+=1
print(count)
print("Something wrong")
# cv2.imwrite("img_"+str(count)+".jpg",f)
except Exception as e:
print("_______-",e)
cv2.imshow("image",f)
if cv2.waitKey(1) & 0xFF == ord("q") :
break
cap.release()
cv2.destroyAllWindows()
def take_screenshot(self,frame,count):
prev = time.time()
cv2.imwrite("screen_shot/img_"+str(count)+".jpg",frame)
1条答案
按热度按时间s3fp2yjn1#
为了每隔n秒捕获一次图像,可以尝试使用datetime库,并找出当前时间和经过时间之间的差值,然后使用cv2的imwrite