OpenCV - Java : inRange function

2020-07-11 06:39发布

问题:

I have my image mRgba and when I do this :

Core.inRange(mRgba, B1, B2, mRgba);

I have the result that I expect : all my RGBA image is thresholded between B1 and B2.

Now I want to do this :

Mat roi = mRgba.submat(rect);
Core.inRange(roi, B1, B2, roi);

And it's not apply on my area rectangle, I try everything since 3 hours I can't find a solution...

回答1:

OK, maybe everybody doesn't care, but after many tries, i found the answer.

Mat roi = new Mat();
roi = mRgba.submat(rect);
Mat roiTmp = roi.clone();

Imgproc.cvtColor(roiTmp, roiTmp, Imgproc.COLOR_RGB2HSV);

Core.inRange(roiTmp, B1, B2, roiTmp);

Imgproc.cvtColor(roiTmp, roi, Imgproc.COLOR_GRAY2BGRA);