[PYTHON] Save the input video from the capture board as an image

Introduction

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.

SnapCrab_NoName_2020-3-22_18-44-35_No-00.png

environment

script

--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

Save the input video from the capture board as an image
Crop Numpy.ndarray and save it as an image
Save the graph drawn by pyqtgraph to an image
Save screenshot of [Python] [Windows] screen as an image
Remove the frame from the image
Understand the function of convolution using image processing as an example
I tried to cut out a still image from the video
Operate Firefox with Selenium from python and save the screen capture
Grayscale image and save as csv
Let's cut the face from the image
The story of making a tool to load an image with Python ⇒ save it as another name
[python] Send the image captured from the webcam to the server and save it
Save dog images from Google image search
Video acquisition / image shooting from a webcam