Ask Your Question
0

Receiving Empty OpenCV Mat images in Android NDK JNI.

asked 2016-05-16 07:58:32 -0600

Capa Master gravatar image

updated 2016-05-17 02:04:23 -0600

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
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-17 04:35:31 -0600

Pranav Buradkar gravatar image

I think it should be

Mat* mGray = (Mat*) GrayImage;
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-16 07:58:32 -0600

Seen: 854 times

Last updated: May 17 '16