Ask Your Question

Receiving Empty OpenCV Mat images in Android NDK JNI.

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

Capa Master gravatar image

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


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 :

           public void onCameraViewStarted(int width, int height) {
                mGray = new Mat();
                mRgba = new Mat();

        public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
                mRgba = inputFrame.rgba();
                mGray = inputFrame.gray();     

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

LOCAL_PATH := /home/Project/jni
include $(CLEAR_VARS)
include /home/Project/OpenCV-2.4.9-android-sdk/sdk/native/jni/
LOCAL_SRC_FILES := process_jni.cpp process.cpp
LOCAL_LDLIBS += -llog  -landroid -ldl :::

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) 


Row  0
Colms 0
Channels 1
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

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

Pranav Buradkar gravatar image

I think it should be

Mat* mGray = (Mat*) GrayImage;
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 634 times

Last updated: May 17 '16