Auto-capture an image from a video in OpenCV using python

对着背影说爱祢 提交于 2019-12-04 13:49:11

In order to continuously view the video, you need to repeat the same part of the code which displays the video first and put it in a while loop. Make sure that the handle to the window is not lost.You can make the capture as a mouse click event and use a tickcount, one before the start of the while loop and one inside the loop. Once the difference between the two tick counts is equal to some pre-defined seconds,capture that frame, use break and come out of the while loop.

You need to add another 'cap.read()' line when the delay ends, as this is the code that actually captures the image.

use threading and define the cv.imshow() separately from your function

import threading
import cv2
def getFrame():
    global frame
    while True:
        frame = video_capture.read()[1]

def face_analyse():
    while True:
#do some of the opeartion you want  

def realtime():
    while True:
        cv2.imshow('Video', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            video_capture.release()
            cv2.destroyAllWindows()
            break

if __name__ == "__main__":
    video_capture = cv2.VideoCapture(cam)
    frame = video_capture.read()[1]

    gfthread = threading.Thread(target=getFrame, args='')
    gfthread.daemon = True
    gfthread.start()
    rtthread = threading.Thread(target=realtime, args='')
    rtthread.daemon = True
    rtthread.start()
    fathread = threading.Thread(target=face_analyse, args='')
    fathread.daemon = True
    fathread.start()

    while True: #keep main thread running while the other two threads are non-daemon
        pass
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!