Add the following code to the code:
Imgproc.cvtColor(imgToProcess, imgToProcess, Imgproc.COLOR_BGR2GRAY); Imgproc.cvtColor(imgToProcess, imgToProcess, Imgproc.COLOR_GRAY2RGBA, 4);
Or you can access the pixels yourself:
for(int i=0;i<imgToProcess.height();i++){ for(int j=0;j<imgToProcess.width();j++){ double y = 0.3 * imgToProcess.get(i, j)[0] + 0.59 * imgToProcess.get(i, j)[1] + 0.11 * imgToProcess.get(i, j)[2]; imgToProcess.put(i, j, new double[]{y, y, y, 255}); } }
source share