How to only display an ROI in a video frame OpenCV java?

asked 2017-11-24 09:29:50 -0500

sam001 gravatar image

updated 2017-11-24 09:31:09 -0500

I am new to OpenCV and so I am still learning some of the functionalities. So, here is what I would like to achieve. I want to load my camera and in the camera frame I just want to keep the area inside the rectangular box to be seen in the camera frame. Anything outside the box should be completely black. How should I go about it. This is what I tried so far.

int centerx = (int) (mrgba.width()*0.5);
    int  centery = (int) (mrgba.height() * 0.5);

   // Rect rect = new Rect(centerx,centery,100,100);

  //  Mat submat = mrgba.submat(rect);

     Imgproc.rectangle(mrgba,new Point(centerx-100,centery - 100),new Point(centerx+100,centery+100),new Scalar(0,0,255) );

/Currently all it does, is that it draws a rectangle at the center of the camera frame but then I dont want anything outside that rectangular frame.
    return mrgba;
edit retag flag offensive close merge delete