ROI OpenCV Android install error

I am trying to figure out how to set ROI for an image in OpenCV on Android. I have done this on other operating systems, so I think HOW I am doing it semantically correct, but there is a bug somewhere.

So far I have tried this

Rect roi = new Rect(0, 0, inputFrame.cols(), inputFrame.rows());
Mat cropped = new Mat(inputFrame, roi);

      

However, I am getting an error somewhere in the OpenCV classes that looks like

Utils.matToBitmap() throws an exception:/home/reports/ci/slave/opencv/modules/java/generator/src/cpp/utils.cpp:107: 
error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width ==
(uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2
(JNIEnv*, jclass, jlong, jobject, jboolean)

      

I call this in the onCameraFrame callback provided by the opencv wrapper class

Not sure how to do this, has anyone successfully done this?

+3


source to share


2 answers


OpenCV for Android (and the new Java API) has its own way of generating ROI.

All you have to do is call the submatrix method of your Mat object. If I am not mistaken, the submat call does not create a copy of this area of ​​the image, if you want to copy you can use copyTo to sub-mask for this purpose.

Mat roi = inputFrame.submat(rowStart, rowEnd, colStart, colEnd);

      

You can call submat in 3 ways, check links for more details:

  • submat (int rowStart, int rowEnd, int colStart, int colEnd)


submat 1

  • submat (Range rowRange, Range colRange)

submat 2

  • submat (Rect roi)

submat 3

+8


source


The error is that you are trying to set the ROI with the same image dimensions, so there is no need for an ROI in this case.

To verify this, you need the following:



Rect roi = new Rect(0, 0, inputFrame.cols() - 1, inputFrame.rows() - 1);
Mat cropped = new Mat(inputFrame, roi);

      

+2


source







All Articles