[ Top page ]

« MPEG video file generation from Caltech dataset | Main | Repetier firmware for a AnyCubic Kossel 3D printer »

MultiMedia

A program that removes bottom part of an MPEG video

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()
Keywords:

TrackBack

TrackBack URL for this entry:
http://www.kanadas.com/mt/mt-tb.cgi/7119

Post a comment

About

This page contains a single entry from the blog posted on January 27, 2016 11:10 PM.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.36