Hi!
I am currently playing around with the OpenCV4Android FaceDetection sample
code. I am currently trying to learn how to add an additional .cpp and
corresponding .h file to the jni folder. I have created both files in the
folder (silplified for explanation purposes here):

"addTwoNumbers.h"

#ifndef WINKDETECTION_H

#define WINKDETECTION_H
int addTwoNumbers(int A, int B); // function prototype for add.h

#endif

"addTwoNumbers.cpp"
int addTwoNumbers(int A, int B)

{
return A + B;
}

"Android.mk"

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#OPENCV_CAMERA_MODULES:=off
#OPENCV_INSTALL_MODULES:=off
#OPENCV_LIB_TYPE:=SHARED
include ../../sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := DetectionBasedTracker_jni.cpp, WinkDetection.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS += -llog -ldl
LOCAL_MODULE := detection_based_tracker
include $(BUILD_SHARED_LIBRARY)

Then, in the "DetectionBasedTracker_jni.cpp" file, I have the following
line to call the add function:

if (addTwoNumbers(a,b) >= 20)
{
LOGD("Size Is Too Big");
}

However, when I go to compile and run the code on my device through
Eclipse, I get the following error:

10-02 19:07:33.312: I/Sample::SurfaceView(32235): Instantiated new class
org.opencv.samples.fd.FdView
10-02 19:07:33.342: I/Sample::FdView(32235): Loaded cascade classifier from
/data/data/org.opencv.samples.fd/app_cascade/lbpcascade_frontalface.xml
10-02 19:07:33.342: D/dalvikvm(32235): Trying to load lib
/data/data/org.opencv.samples.fd/lib/libdetection_based_tracker.so
0x414451b8
10-02 19:07:33.342: D/dalvikvm(32235): Shared lib
'/data/data/org.opencv.samples.fd/lib/libdetection_based_tracker.so'
already loaded in same CL 0x414451b8
10-02 19:07:33.342: W/dalvikvm(32235): No implementation found for native
Lorg/opencv/samples/fd/DetectionBasedTracker;.nativeCreateObject:(Ljava/lang/String;I)J
10-02 19:07:33.342: D/AndroidRuntime(32235): Shutting down VM
10-02 19:07:33.342: W/dalvikvm(32235): threadid=1: thread exiting with
uncaught exception (group=0x40cc1300)
10-02 19:07:33.342: E/AndroidRuntime(32235): FATAL EXCEPTION: main
10-02 19:07:33.342: E/AndroidRuntime(32235):
java.lang.UnsatisfiedLinkError: Native method not found:
org.opencv.samples.fd.DetectionBasedTracker.nativeCreateObject:(Ljava/lang/String;I)J
10-02 19:07:33.342: E/AndroidRuntime(32235): at
org.opencv.samples.fd.DetectionBasedTracker.nativeCreateObject(Native
Method)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
org.opencv.samples.fd.DetectionBasedTracker.<init>(DetectionBasedTracker.java:10)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
org.opencv.samples.fd.FdView.<init>(FdView.java:91)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
org.opencv.samples.fd.FdActivity$1.onManagerConnected(FdActivity.java:39)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:206)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1097)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1114)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
android.os.Handler.handleCallback(Handler.java:615)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
android.os.Handler.dispatchMessage(Handler.java:92)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
android.os.Looper.loop(Looper.java:137)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
android.app.ActivityThread.main(ActivityThread.java:4745)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
java.lang.reflect.Method.invokeNative(Native Method)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
java.lang.reflect.Method.invoke(Method.java:511)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-02 19:07:33.342: E/AndroidRuntime(32235): at
dalvik.system.NativeStart.main(Native Method)


Does anybody know what I am doing wrong?


--

Search Discussions

  • Alexander Smorkalov at Oct 4, 2012 at 5:30 am
    Hello SchrodingersCat,

    What version of OpenCV do you use? Is it release 2.4.2 or you build it from
    trunk?
    It looks like you forgot to rebuild native part of example. You need just
    execute "ndk-build" in project folder. Also you can add ndk-build as build
    step if CDT already installed. See
    tutorial<http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/android_dev_intro.html#android-dev-intro>for
    more details.

    BTW, OpenCV team introduces Q&Q service http://answers.opencv.org.

    Regards,
    Alexander

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-opencv @
categoriesandroid
postedOct 2, '12 at 7:15p
activeOct 4, '12 at 5:30a
posts2
users2
websiteandroid.com

People

Translate

site design / logo © 2018 Grokbase