Ask Your Question

Revision history [back]

Empty Mat images in JNI.

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);
} JNI :

JNIEXPORT void JNICALL Java_com_example_process_ProcessImages (JNIEnv * jenv, jclass, jlong thiz, jlong GrayImage) {

            Mat& leftimage = *(Mat*) GrayImage;

            LOGD("Rows %d\n", GrayImage.rows);
            LOGD("Colms %d\n", GrayImage.cols);
            LOGD("Channels %d\n",GrayImage.channels());

}

Output: Row 0 Colms 0 Channels 1

Receiving Empty 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(); } 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& leftimage = *(Mat*) GrayImage;

            LOGD("Rows %d\n", GrayImage.rows);
            LOGD("Colms %d\n", GrayImage.cols);
            LOGD("Channels %d\n",GrayImage.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

click to hide/show revision 3
No.3 Revision

updated 2016-05-17 01:50:50 -0600

berak gravatar image

Receiving Empty 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();

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& leftimage = *(Mat*) GrayImage;

             LOGD("Rows %d\n", GrayImage.rows);
             LOGD("Colms %d\n", GrayImage.cols);
             LOGD("Channels %d\n",GrayImage.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

-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;

android.util.Log; public class Process { ................. public void process(Mat Grayimage) ProcessImages(Grayimage.getNativeObjAddr()); ..................... }

Output: }

Output:

Row  0
Colms 0
Channels 1

1

Receiving Empty 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& leftimage mGray = *(Mat*) GrayImage;

                LOGD("Rows %d\n", GrayImage.rows);
mGray.rows);
                LOGD("Colms %d\n", GrayImage.cols);
mGray.cols);
                LOGD("Channels %d\n",GrayImage.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

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