Opencv Android Java Matrix Submatrix (roi Region Of Interest)
I've mRgba Matrix and a Rect r (something recognized in the frame) I want a sub-matrix of this part of the frame which is defined by the Rect r. when I use it like this: sub = mRgb
Solution 1:
Your code does not work as you expected because it is impossible to change number of colors in-place. You need a temporary matrix to make it work:
Mat tmp;
Imgproc.cvtColor(sub, tmp, Imgproc.COLOR_RGBA2GRAY); //make it gray
Imgproc.cvtColor(tmp, sub, Imgproc.COLOR_GRAY2RGBA); //change to rgb
Solution 2:
sub = mRgba.submat(r);
Imgproc.cvtColor(sub, sub, Imgproc.COLOR_RGBA2GRAY, 1); //make it gray
Imgproc.cvtColor(sub, sub, Imgproc.COLOR_GRAY2RGBA, 4); //change to rgb
sub.copyTo(mRgba.submat(r));
ok this seems to do the trick :) it copies the changed subpicture/matrix back in the region of the source.. (what is normally done with setROI and copyto)
Post a Comment for "Opencv Android Java Matrix Submatrix (roi Region Of Interest)"