How to convert rectangle color (ROI) to matrix with OpenCV Java?

I am trying to convert color to ROI matrix with OpenCV Java with the following code

public Mat detect(Mat image){
    Rect roi = new Rect(new Point(50, 50), new Point(image.width() - 50, image.height() - 50));
    Mat mask = image.submat(roi);
    Mat temp = new Mat();
    Imgproc.cvtColor(mask, temp, Imgproc.COLOR_BGRA2GRAY,0);
    temp.copyTo(mask);
    return image;
}

But the result is the same as the given image. If I change the call to Imgproc.cvtColor () with the effect Imgproc.medianBlur (), for example:

    ...
    Imgproc.medianBlur(mask, temp, 11);
    ... 

A blurred rectangle appears. I think that during the Imgproc.cvtColor () process, the links to the original image are replaced by some recently created ones. So, how else can you convert the ROI color to a matrix without losing links?

I appreciate any help, thanks!

PS: I wanted to add a few exemplary images, but my reputation is not high enough. I regret it and hope you can imagine my problem even without samples.

+4
1

, 1- 4- .

, .

(sub) img rgba,

Mat temp = new Mat();
Imgproc.cvtColor(mask, temp, Imgproc.COLOR_BGRA2GRAY,0);
Mat temp_rgba = new Mat();
Imgproc.cvtColor(temp, temp_rgba, Imgproc.COLOR_GRAY2BGRA,0);
temp_rgba.copyTo(mask);
+1

All Articles