Ask Your Question
0

Convert rgba to hsv in android (JNI)

asked 2013-10-27 04:44:09 -0600

lobi gravatar image

updated 2013-10-27 07:29:59 -0600

Hello,

i'm trying to learn OpenCV with JNI.

I made a program which tracks an object in Java for android, but now I like to make the same code in C++.

Firstly I would like to convert RGBA to HSV and show this on my screen, but when I run my application I get this error.

Sorry!
The Application Trcker (process com.slani.tracker) has stopped unexpectedly. Please try again.
Force Close

Here is my onCameraFrame method.

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    Mat rgba = inputFrame.rgba();
    Mat hsv = new Mat()

    findObject(rgba.getNativeObjAddr(), hsv.getNativeObjAddr());
    return hsv;
}

Here is my JNI

#include <jni.h>
#include <opencv2/highgui/highgui.hpp">
#include <opencv/cv.h">


extern “C” {
    JNIEXPORT void JNICALL Java_com_slani_tracker_OpenCamera_findObject(JNIEnv * jenv, jclass, jlong addRgba, jlong addHsv)
    {

        Mat& rgba = *(Mat*)addRgba;
        Mat& hsv = *(Mat*)addHsv;

        cvtColor(rgba, hsv,CV_RGBA2HSV);

}
}

Here is my log file http://bpaste.net/show/21RTfuqxs8wtIMaH2jNL/

Can someone please tell me what I'm doing wrong?

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2013-10-27 07:28:59 -0600

Daniil Osokin gravatar image

Implementation of your findObject method isn't found. I'm think, you've defined implementation in header file, but you need to implement it in .cpp file, then build a native library through ndk-build and load this library in Java code. See "Face detection" sample for details.

edit flag offensive delete link more

Comments

Thanks for your answer, but I'm not sure if I understand it. I implement findObject method in .cpp file in jni folder.

When I run my project ndk build successfully. * Build of configuration Debug for project Tracker *

/home/slani/code/android-ndk-r9

* Build Finished *

I also include this in my java file

public native void findObject(long rgbaAdd, long hsvAddr);

lobi gravatar imagelobi ( 2013-10-27 07:53:40 -0600 )edit

Ok. I made a mistake in Android.mk file. I misspell my cpp file. But now I get this error

In file included from /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv/cv.h:64:0, from jni/detect_jni.cpp:2: /home/slani/code/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp:56:21: fatal error: algorithm: No such file or directory compilation terminated. make: * [obj/local/armeabi/objs/detect_jni/detect_jni.o] Error 1

lobi gravatar imagelobi ( 2013-10-27 09:28:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-10-27 04:44:09 -0600

Seen: 1,515 times

Last updated: Oct 27 '13