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

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

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 = cap.read(frame); 

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

    return 0;

}

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

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-23 04:39:50.963046

Comments

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

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