Skip to content

Access a Video File

Andrés Solís Montero edited this page Oct 18, 2015 · 2 revisions

Access a Video File

You can specify a video file by doing the following:

int main(int argc, const char * argv[])
{
    
    auto processFrame = [](size_t frameN, Mat &input, Mat &output){
        GaussianBlur(input, output, Size(7,7), 1.5, 1.5);
        Canny(output, output, 0, 30, 3);
    };
    
    Ptr<Input> input = new VideoInput("path/to/your/videofile.mpg");
  
    Processor processor;
    processor.setInput(input);
    processor.setProcess(processFrame);
    processor.run();
    
    return 0;
}

The VideoInput class takes a string as its first argument, the filename – name of the opened video file (eg. video.avi).

The setInput method sets the Processor class to use the input instance (i.e. VideoInput).

processor.setInput(input)

You can force the image size of your input by passing a second argument specifying the desired resolution. If you would like to use the device original resolution a value of Size(-1,-1) should be passed (i.e. default value Size(-1,-1)).

Ptr<Input> input = new VideoInput("path/to/your/video", Size(640,480));

A third argument specifies the OpenCV color space conversion code to apply to the images. By default no code conversion is applied to the images generated by the input device (i.e. default value - 1).

Ptr<Input> input = new VideoInput(0, Size(640,480),CV_RGB2GRAY);

This is useful in the case your video file is in a different color spectrum to the one you would like to use in your algorithm. (e.g. CV_GRAY2RGB, CV_RGB2HLS, ... etc)

Clone this wiki locally