Home>

Regarding recording with Opencv, I would like to change what is recorded at 640 * 480 by default to 1280 * 720.

Corresponding source code
#!/usr/bin/env python3
import cv2
import time
import datetime
import shutil
import os
import numpy as np
car_cascade = cv2.CascadeClassifier ("cars.xml")
cap = cv2.VideoCapture (0)
width = int (cap.get (3))
height = int (cap.get (4))
fourcc = cv2.VideoWriter_fourcc ('H', '2', '6', '4')
bfdt = nowdt = datetime.datetime.now ()
filename ='cap' + nowdt.strftime ('% Y% m% d_% H% M') +'.mp4'
out = cv2.VideoWriter (filename, fourcc, 15, (width, height))
path ='/ home/pi /'
Edge = np.zeros (4, dtype = int)
while (True):
    ret, frame = cap.read ()
    FindPerson = car_cascade.detectMultiScale (frame) # Perform object recognition
    for (Edge [0], Edge [1], Edge [2], Edge [3]) in FindPerson: # Enclose the detected person in a square
        # Enclose in a square
        cv2.rectangle (frame, (Edge [0], Edge [1]), (Edge [0] + Edge [2], Edge [1] + Edge [3]), (255, 0, 0), 2) #Image from left, upper left coordinates, lower right coordinates, color, thickness
        text = "car" # Set the characters to be displayed together
        font = cv2.FONT_HERSHEY_SIMPLEX #Set font
        cv2.putText (frame, text, (Edge [0], Edge [1]), font, 1, (255,255,255), thickness = 2) # Embed in video
    out.write (frame)
    # cv2.imshow ('frame', frame)
    nowdt = datetime.datetime.now ()
    border_time = bfdt + datetime.timedelta (minutes = 1)
    if border_time<= nowdt:
        bfdt = nowdt
        shutil.move (path + filename,'./movie')
        filename ='cap' + nowdt.strftime ('% Y% m% d_% H% M') +'.mp4'
        out = cv2.VideoWriter (filename, fourcc, 15, (width, height))
    if cv2.waitKey (1)&0xFF == ord ('q'):
        break
cap.release ()
cv2.destroyAllWindows ()
Supplementary information (FW/tool version, etc.)

python 3.7.3