Receiving Empty OpenCV Mat images in Android NDK JNI.
Hi,
We are trying to get an image (OpenCV :: MAT) from Android application to Android JNI. At android level the image dump is taken and Mat is having data. But at JNI level after typecasting (Mat*) the rows and columns are getting zero with channel 1. Here with putting the snapshot of the process function.
Kindly help us too resolve the same.
JAVA code :
{
@Override
public void onCameraViewStarted(int width, int height) {
mGray = new Mat();
mRgba = new Mat();
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
ps.process(mGray);
}
}
Android JNI :
JNIEXPORT void JNICALL Java_com_example_process_ProcessImages
(JNIEnv * jenv, jclass, jlong thiz, jlong GrayImage) {
Mat& mGray = *(Mat*) GrayImage;
LOGD("Rows %d\n", mGray.rows);
LOGD("Colms %d\n", mGray.cols);
LOGD("Channels %d\n",mGray.channels());
}
Android.mk ::::
LOCAL_PATH := /home/Project/jni
include $(CLEAR_VARS)
include /home/Project/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_CFLAGS := -std=gnu++0x -I$(OPENCV_INCLUDE) #-I$(BOOST_INCLUDE)
LOCAL_MODULE := Process
LOCAL_EXPORT_LDLIBS := $(LOCAL_LDLIBS)
LOCAL_SRC_FILES := process_jni.cpp process.cpp
LOCAL_LDLIBS += -llog -landroid -ldl
Process_Image.java :::
package com.example.process;
import org.opencv.core.Mat;
import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfFloat4;
import org.opencv.core.MatOfPoint2f;
import android.util.Log;
public class Process {
.................
public void process(Mat Grayimage)
ProcessImages(Grayimage.getNativeObjAddr());
.....................
}
Output:
Row 0
Colms 0
Channels 1