Is it possible to crop raw video before extracting all the frames ?

asked 2018-07-30 18:23:25 -0500

raisa_ gravatar image

I want to crop a certain area of my raw video before extract the frames. I don't want to use external cropping video because I need the video to be raw for processing. Is it possible to crop a certain area before frame extraction ? I read about ROI for images, is it possible for video too ?

Here's my extraction code :

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <string>
#include <sstream>

using namespace cv;
using namespace std;
int c = 0;
string int2str(int &);

int main(int argc, char **argv) {
    string s;

    VideoCapture cap("test_video.mp4"); 
    if (!cap.isOpened())  
        cout << "Cannot open the video file" << endl;
        return -1;

    double fps = cap.get(CV_CAP_PROP_FPS); 

    cout << "Frame per seconds : " << fps << endl;

    namedWindow("MyVideo", CV_WINDOW_NORMAL); 
    resizeWindow("MyVideo", 600, 600);
    while (1)
        Mat frame;
        Mat Gray_frame;
        bool bSuccess =; 

        if (!bSuccess) 
            cout << "Cannot read the frame from video file" << endl;
        s = int2str(c);
        //cout<<("%d\n",frame )<<endl;
        imshow("MyVideo", frame); 
        imwrite("frame" + s + ".jpg", frame);
        if (waitKey(30) == 27) 
            cout << "esc key is pressed by user" << endl;

    return 0;


string int2str(int &i) {
    string s;
    stringstream ss(s);
    ss << i;
    return ss.str();
edit retag flag offensive close merge delete


You can read this and then you will find that the answer is no.

LBerger gravatar imageLBerger ( 2018-07-31 00:16:34 -0500 )edit