简体   繁体   English

每 5 秒从视频中捕获图像,并使用 Python 和 OpenCV 保存图片

[英]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.

相关问题 使用python在OpenCV中自动捕获视频中的图像 - Auto-capture an image from a video in OpenCV using python 无法在 macOS 中使用 OpenCV 捕获和保存视频 - Cannot capture and save video using OpenCV in macOS 如何在每5秒钟的相机中使用opencv python和Raspbery Pi 3捕获图片? - How to capture a picture after every 5 seconds of camera using opencv python and Raspbery Pi 3? 从视频帧中采样并将它们保存为图像 - python openCV - Sampling from video frames and save them as an image - python openCV 使用 Python OpenCV 将实时视频流中检测到的二维码保存为图像 - Save detected QR code from live video stream as an image using Python OpenCV 在 opencv 中捕获并保存图像 - capture and save image in opencv 无法在Ubuntu上使用OpenCV和Python捕获视频 - Failing to capture video using OpenCV and Python on Ubuntu 每 10 秒后从视频文件中捕获一帧 - capture one frame from a video file after every 10 seconds 如何从始终运行的视频中每 n 秒捕获一次图像? - How to capture images every n seconds from always running video? 在python中使用opencv2将使用mss捕获的屏幕捕获部分保存到视频 - Save capture part of screen using mss to video using opencv2 in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM