1 | initial version |
After some research and experiment, finally i find the light, here it is. you just need to get the image back to the default type. like this :
for (Rect r : faces){
Core.rectangle(mRgba, r.tl(), r.br(), new Scalar(0, 255, 0, 255), 3);
Mat roi = new Mat();
roi = mRgba.submat(r);
Mat gray = new Mat();
Imgproc.cvtColor(roi, gray, Imgproc.COLOR_RGB2GRAY,1);
Mat gray_f = new Mat();
gray.convertTo(gray_f, CvType.CV_32F, 1.0/255, 0);
Mat final = new Mat();
gray_f.convertTo(final, CvType.CV_8U, 255, 0);
Imgproc.cvtColor(final, roi, Imgproc.COLOR_GRAY2RGB,0);
Imgproc.cvtColor(roi, roi, Imgproc.COLOR_RGB2RGBA,0);
Mat kotak = new Mat();
kotak = mRgba.colRange(r.x, r.x+r.width).rowRange(r.y, r.y+r.height);
roi.copyTo(kotak);
} }
This is the Queen of This Answer :
Mat final = new Mat();
gray_f.convertTo(final, CvType.CV_8U, 255, 0);