Search code examples
c++opencvroi

Opencv ROI fills more than it should


When I try to set frame ROI it fills up empty pixels, from given x to the end of input image. ROI is extracted well, can anyone tell me why isn't it 30 pixels wide as it should be? Image is resized from original size to 640x360.

resize(frame, frame, Size(), 0.5, 0.5, INTER_LINEAR);
Mat roi = img(Rect(460, 0, 30, 300));

Image is shown below. Original image to the left and ROI to the right


Solution

  • Your ROI looks fine. The cv::Rect ctor takes: xOffset, yOffset, width and height. You asked for width 30 and height 300.

    However, on some UI systems there is a minimum window width/height/size. Displaying images smaller than this minimum will add an extra blank region on the side which is not part of the actual cv::Mat.