3

I want to use ROI in OpenCV for Android.

This is code true?

Mat image = new Mat();
Mat imageRIO = new Mat();
Rect roi = new Rect(300, 50, 50, 10);

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    image = inputFrame.gray();

    image.submat(roi);  //set roi
    image.copyTo(imageRIO);
    return imageRIO;
 }
Andy
  • 61,948
  • 13
  • 68
  • 95
user3104589
  • 137
  • 2
  • 11
  • possible duplicate of [Error setting ROI OpenCV Android](http://stackoverflow.com/questions/14695428/error-setting-roi-opencv-android) – Rui Marques Jan 19 '14 at 16:08

1 Answers1

5

I am not sure exactly what you are trying to do, but submat() returns a Mat that you need and you are not assigning it to anything. image.copyTo() copies image not the submat you extracted in the previous line.

You could simply do this:

Rect roi = new Rect(300, 50, 50, 10);

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    return new Mat(inputFrame.gray(), roi);
}
Bull
  • 11,771
  • 9
  • 42
  • 53