Displaying Mat Image in Android Screen
Hei, I have a little problem when i try to convert opencv c++ to opencv4android. here it is :
Android Source Code -- Online Processing
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_BGR2GRAY,1);
Mat gray_f = new Mat();
gray.convertTo(gray_f, CvType.CV_32F, 1.0/255, 0);
Imgproc.cvtColor(gray_f, roi, Imgproc.COLOR_GRAY2BGR,0);
Imgproc.cvtColor(roi, roi, Imgproc.COLOR_BGR2BGRA,0);
Mat kotak = new Mat();
kotak = mRgba.colRange(r.x, r.x+r.width).rowRange(r.y, r.y+r.height);
roi.copyTo(kotak);
}
C++ Source Code -- Offline Processing
cv::Mat image = cv::imread("hand.jpg",1);
cv::imshow("Src", image);
cv::cvtColor(image, src, CV_BGR2GRAY);
src.convertTo(src_f, CV_32F, 1.0/255, 0);
cv::imshow("src", src);
cv::imshow("src_f", src_f);
This the result of C++ :
This the result of Android :
I Think that's above code have the same result, but when i run above code in pc and in andrioid, they haven't same result. i don't know way, any body help me please to explain it. Thanks in Advance... your little help should make my life better.. :)
UPDATED
After some hard of research, i was find my final problem, i think i wrong to display Mat image, just look at this : http://stackoverflow.com/a/9471411/1593269, if i want to convert BGR to Gray image and then display it on the android screen i need this :
Imgproc.cvtColor(image, dst4, Imgproc.COLOR_BGR2GRAY); //Convert BGR to GRAY
Imgproc.cvtColor(dst4, image, Imgproc.COLOR_GRAY2BGR); **//Confuse with This**
Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2BGRA); //To compate with default android standard (4 channel), so we need to change from 1 channel to 4 channel before we display
Somebody please help me to understand what the mean :
Imgproc.cvtColor(dst4, image, Imgproc.COLOR_GRAY2BGR); **//Confuse with This**
and For what this row of code ? if i don't write that's code, it will always force close. Once again, I am trying to convert mat of gray image to CV_32F, then i want to display it on the screen, and i am trying to figure it out by this :
Imgproc.cvtColor(imgmat, src, Imgproc.COLOR_RGB2GRAY,0);
src.convertTo(src_f, src_f.type(), 1.0/255, 0);
Imgproc.cvtColor(dest_mag, imgmat, Imgproc.COLOR_GRAY2RGB, 0);
Imgproc.cvtColor(imgmat, imgmat, Imgproc.COLOR_RGB2RGBA, 0);
it will run smoothly on the screen but without desired result.(desired result : gray image with CV_32F (java primitive array))