It is a script that periodically saves the input video from the capture board as an image. I created it because I wanted to get screenshots of the game video (Nitendo Switch) on a regular basis.

--Get video from capture board with OpenCV
--Get captured image every second
-> Switch is 60fps (every 1/60 second), so save the image when count is a multiple of 60
--Resize the acquired frame to HD size and save it
-> Video is output in Full HD, but I wanted a captured image in HD
 capture.py
import cv2
import datetime
#Get a VideoCapture object
#If you are connected to a webcam etc. in addition to Capbo, you may need to specify another number
capture = cv2.VideoCapture(0)
print(capture.isOpened())
capture.set(3, 1920)
capture.set(4, 1080)
count = 0
while(True):
    ret, frame = capture.read()
    cv2.imshow('frame', frame)
    count += 1
    print(count)
    if count % 60 == 0:
        dt_now = datetime.datetime.now()
        # 1280 *Convert and save to 720 captured images
        resized = cv2.resize(frame, (1280, 720))
        #Save as jpg in the specified folder
        cv2.imwrite('H:/capture/'+ dt_now.strftime('%Y%m%d-%H%M%S')+'.jpg', resized)
    # "q"Key or ctrl+Stop capture at C
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
capture.release()
cv2.destroyAllWindows()
        Recommended Posts