I tried to split RGB image (http://www.kavim.com/uploads/signs/tn__51A2376.JPG) into seperate channels, threshold each channel and merge it back together resulting in something like this.
What I fail to understand is, why, if I try to convert the merged image into grayscale I get this color threshold output (and not a grayscale image instead).
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat rgba = inputFrame.rgba();
Size sizeRgba = rgba.size();
Mat grayInnerWindow1;
Mat rgbaInnerWindow;
int rows = (int) sizeRgba.height;
int cols = (int) sizeRgba.width;
int left = cols / 8;
int top = rows / 8;
int width = cols * 3 / 4;
int height = rows * 3 / 4;
rgbaInnerWindow = rgba.submat(top, top + height, left, left + width);
ArrayList<Mat> channels = new ArrayList<Mat>(3);
Mat src1= Mat.zeros(rgbaInnerWindow.size(),CvType.CV_8UC3);
Core.split(rgbaInnerWindow, channels);
Mat b = channels.get(0);
Imgproc.threshold(b, b, 0, 70, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU);
Mat g = channels.get(1);
Imgproc.threshold(g, g, 0, 70, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU);
Mat r = channels.get(2);
Imgproc.threshold(r, r, 90, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU);
Core.merge(channels, src1);
Imgproc.medianBlur(src1, src1, 3);
Imgproc.threshold(src1,rgbaInnerWindow,0, 255, Imgproc.THRESH_BINARY);
Imgproc.cvtColor(rgbaInnerWindow,src1, Imgproc.COLOR_BGR2GRAY);
rgbaInnerWindow.release();
return rgba;
}
}