Ask Your Question

Revision history [back]

take a look at the code below

#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

using namespace cv;

int main( int argc, char** argv )
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera

        Mat roi = frame(Rect(frame.cols/4,frame.rows/4,frame.cols/2,frame.rows/2));
        frame = frame / 2;
        roi = roi * 2;
        imshow("VideoCapture", frame);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}