Ask Your Question

Revision history [back]

The the problem in above code is that you are trying to copy single channel Mat (GRAY) to multi channel Mat (RGBA).

So you need to convert GRAY to RGBA before copying back to original RGBA image.

Change your code to

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
   Mat image = inputFrame.rgba();
   Rect roi = new Rect(300, 50, 50, 10);
   Mat sub =image.submat(roi); 
   Imgproc.cvtColor(sub, sub, Imgproc.COLOR_RGBA2GRAY);
   Imgproc.cvtColor(sub, sub, Imgproc.COLOR_GRAY2RGBA);
   sub.copyTo(image.submat(roi));
   return image;
}

Copied from stackoverflow to provide a solution if the topic would disappear...