[英]Capture image from video every 5 seconds, and save picutres using Python & OpenCV
The person who is making the ocr program.制作ocr程序的人。 I want to capture the image of the video every 5 seconds and inspect it in real time.我想每 5 秒捕获一次视频图像并实时检查。
cap = cv2.VieoCapture(0)
while(True)
ret,frame = cap.read()
cv2.imwrite('Test.png'),frame,params=[cv2.IMWRITE_PNG_COMPRESSION,2]
ocrcheck() #Function to read 'Test.png' and check with ocr program
I want to get a frame in real time every 5 seconds, save it and print the saved image to the ocr program.我想每5秒实时获取一帧,保存并将保存的图像打印到ocr程序。 Please tell me the answer请告诉我答案
You could use cv2.waitKey(delay_in_ms) or time.sleep(delay_in_seconds) to sleep for a given amount of time.您可以使用 cv2.waitKey(delay_in_ms) 或 time.sleep(delay_in_seconds) 休眠给定的时间。 Consider also the following: your ocrcheck() function and cv2.imwrite will spend some time, so it's better to sleep not for 5 seconds, but for (5 - time_spent), where time_spent is the time spent on calling these two functions.还要考虑以下几点:您的 ocrcheck() function 和 cv2.imwrite 会花费一些时间,所以最好不要睡 5 秒,而是睡 (5 - time_spent),其中 time_spent 是调用这两个函数所花费的时间。 Example:例子:
while(True)
start_time = time.time()
ret,frame = cap.read()
cv2.imwrite('Test.png'),frame,params=[cv2.IMWRITE_PNG_COMPRESSION,2]
ocrcheck() #Function to read 'Test.png' and check with ocr program
spent = time.time() - start_time # how much you spent on calling functions above
time.sleep(5 - spent) # sleep for a rest of time
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.