How Can I Capture Screenshot of User from Live Stream After a Specific Interval

761 views Asked by At
import time
from datetime import datetime
from cv2 import *
import schedule


def main():

    capture = cv2.VideoCapture(0)
    while True:
        success, image = capture.read()
        cv2.imshow("Live Feed", image)
        cv2.waitKey(1)
        schedule.every(10).seconds.do(take_screenshot())

def take_screenshot():

    cv2.imwrite(f"test-{str(datetime.now())}",image)



if __name__ == '__main__':
    main()

I am working on a project of my own research . Web camera is open for 60 minutes So I want to capture the user picture after every 1 minute. I want to take screenshot of live feed after every 1 minute. I tried some videos and website. but found this schedule can solve my issue but I'm getting error of Image is not defined. How do I can pass the value of image to screenshot function or how I can take screenshot after every specific interval and save in directory

1

There are 1 answers

0
Dev On

If you are using webcam you should modify the code.

in OpenCV for laptop camera to use:

capture = cv2.VideoCapture(0)

and for webcam use:

capture = cv2.VideoCapture(1)

0 or 1 is used for which camera or webcam you want to use in case of multiple cam.