A program that can be used when changing video size by removing part of each frame, which is required for, for example, image recognition. The usage is as follows.
clip(inFile, outFile, options...)
inFile is the input file, andoutFile is the output file. outHeightMin and outHeightMax specifies the vertical range of the output frame. outWidth is the width of the output.
### Clipping video -- reducing the vertical size ### import cv2, cv, time import numpy as np def createPedestrianWriter(outFile, width, height): writer = cv2.VideoWriter() writer.open(outFile, cv.CV_FOURCC('P','I','M','1'), fps = 30, frameSize = (width, height), isColor = False) return writer def clip(inFile, outFile, outHeightMin = 80, outHeightMax = 280, outWidth = 1280): reader = cv2.VideoCapture(inFile) writer = createPedestrianWriter( outFile, width = outWidth, height = outHeightMax - outHeightMin ) ret, oframe = reader.read() while ret: frame = cv2.cvtColor(oframe, cv2.COLOR_BGR2GRAY) writer.write(frame[outHeightMin:outHeightMax]) ret, oframe = reader.read()