Converting Bitmap to Mat and passing it through JNI
Hello.
I've seen the same problem here but I didn't find a good solution for me.
I'm trying to pass one Bitmap to JNI as:
String name = String.valueOf((int)i+1) + ".jpg";
Bitmap image = AssetBitmapFile(name, this);
image = Bitmap.createScaledBitmap(image, 500, 500, false);
Mat imageMat = new Mat(500, 500, CvType.CV_8U);
System.out.println("width: " + image.getWidth() + " height: " + image.getHeight());
Utils.bitmapToMat(image, imageMat);
Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_RGBA2GRAY);
imageMat.convertTo(imageMat, CvType.CV_8U);
System.out.println("infoMat: " + imageMat);
openCV.setTrainedImages(name, imageMat);
and the console shows:
12-08 16:03:35.742 12466-12466/com.example.try I/System.out﹕ width: 500 height: 500
12-08 16:03:35.742 12466-12466/com.example.try I/System.out﹕ infoMat: Mat [ 500 * 500 * CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x725c8300, dataAddr=0x725cc010 ]
and on my JNI bridge I do:
Mat* imageMat = (Mat*)image;
__android_log_print(ANDROID_LOG_INFO, "TAG", to_text(imageMat->rows).c_str());
and the result is :
12-08 16:03:35.742 12466-12466/com.example.try I/TAG﹕ 1933574177
but it's really 500.
What am I doing bad? I'm using the same code than other projects that I've done and the other worked fine. This is not working fine... it's weird!
thank you very much.