Issue
can you help me handle my errors? I have read a lot of tips how to fix them but nothing helped me. I also know that there are similar question already asked but they didnt help me. So I give a chance to ask you:
I am trying to make Android application what takes Image from gallery and call native function written in c++ to make it grey.
In my main activity is:
static {
if(!OpenCVLoader.initDebug())
{
Log.e("tom", "Tomasku opencv problem static");
}
else
{
Log.e("tom", "OPENCV NACITANE");
System.loadLibrary("halgorithm");
}
}
***In the same Activity I call another activity(EditorActivity):
Intent i = new Intent(this, EditorActivity.class);
...
i.putExtra("path", selectedImagePath); //path to image from gallery
startActivity(i);
***In my EditorActivity:
...
public native int fce(long matAddrRgba, long matAddrGray);
...
fce(image.getNativeObjAddr(), image_gray.getNativeObjAddr());
// and here it crashes
**In my halgorithm.cpp
#include <jni.h>
#include <string.h>
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
//using namespace std;
using namespace cv;
extern "C"
{
JNIEXPORT jint JNICALL Java_com_example_hematoma_MainActivity_fce(JNIEnv*, jobject, jlong addrRgba, jlong addrGray) {
Mat& mRgb = *(Mat*)addrRgba;
Mat& mGray = *(Mat*)addrGray;
int conv;
jint retVal;
conv = toGray(mRgb, mGray);
retVal = (jint)conv;
return retVal;
}
}
int toGray(Mat img, Mat& gray)
{
cvtColor(img, gray, CV_RGBA2GRAY); // Assuming RGBA input
if (gray.rows == img.rows && gray.cols == img.cols)
{
return 1;
}
return 0;
}
**In my Android.mk
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=on
include /home/nemesis/adt-bundle-linux-x86_64-20140702/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := halgorithm
LOCAL_SRC_FILE := halgorithm.cpp
LOCAL_C_INCLUDES := /home/nemesis/adt-bundle-linux-x86_64-20140702/OpenCV-2.4.10-android-sdk/sdk/native/jni/include
include $(BUILD_SHARED_LIBRARY)
***LogCat
04-30 13:16:28.320: W/dalvikvm(3863): No implementation found for native Lcom/example/hematoma/EditorActivity;.fce (JJ)I
04-30 13:16:28.320: D/AndroidRuntime(3863): Shutting down VM
04-30 13:16:28.320: W/dalvikvm(3863): threadid=1: thread exiting with uncaught exception (group=0x40185760)
04-30 13:16:28.320: E/AndroidRuntime(3863): FATAL EXCEPTION: main
04-30 13:16:28.320: E/AndroidRuntime(3863): java.lang.UnsatisfiedLinkError: fce
04-30 13:16:28.320: E/AndroidRuntime(3863): at com.example.hematoma.EditorActivity.fce(Native Method)
04-30 13:16:28.320: E/AndroidRuntime(3863): at com.example.hematoma.EditorActivity$3.onClick(EditorActivity.java:166)
04-30 13:16:28.320: E/AndroidRuntime(3863): at android.view.View.performClick(View.java:3110)
04-30 13:16:28.320: E/AndroidRuntime(3863): at android.view.View$PerformClick.run(View.java:11934)
04-30 13:16:28.320: E/AndroidRuntime(3863): at android.os.Handler.handleCallback(Handler.java:587)
04-30 13:16:28.320: E/AndroidRuntime(3863): at android.os.Handler.dispatchMessage(Handler.java:92)
04-30 13:16:28.320: E/AndroidRuntime(3863): at android.os.Looper.loop(Looper.java:132)
04-30 13:16:28.320: E/AndroidRuntime(3863): at android.app.ActivityThread.main(ActivityThread.java:4123)
04-30 13:16:28.320: E/AndroidRuntime(3863): at java.lang.reflect.Method.invokeNative(Native Method)
04-30 13:16:28.320: E/AndroidRuntime(3863): at java.lang.reflect.Method.invoke(Method.java:491)
04-30 13:16:28.320: E/AndroidRuntime(3863): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
04-30 13:16:28.320: E/AndroidRuntime(3863): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
04-30 13:16:28.320: E/AndroidRuntime(3863): at dalvik.system.NativeStart.main(Native Method)
Thanks in advance!
****************************EDITED***********************
After your suggestions I changed:
***In Android.mk:
JNIEXPORT jint JNICALL
Java_com_example_hematoma_**EditorActivity**_fce(JNIEnv*, jobject, jlong addrRgba, jlong addrGray) {...}
***In EditorActivity: I am calling System.loadLibrary("halgorithm") before native methode.
static {
if(!OpenCVLoader.initDebug())
{
Log.e("tom", "Tomasku opencv problem static");
}
else
{
Log.e("tom", "OPENCV NACITANE");
System.loadLibrary("halgorithm");
}
}
But it didnt fixed my error. There is the same error :/
***LogCat
04-30 13:36:21.760: W/dalvikvm(4255): No implementation found for native Lcom/example/hematoma/EditorActivity;.fce (JJ)I
04-30 13:36:21.760: D/AndroidRuntime(4255): Shutting down VM
04-30 13:36:21.760: W/dalvikvm(4255): threadid=1: thread exiting with uncaught exception (group=0x40185760)
04-30 13:36:21.760: E/AndroidRuntime(4255): FATAL EXCEPTION: main
04-30 13:36:21.760: E/AndroidRuntime(4255): java.lang.UnsatisfiedLinkError: fce
04-30 13:36:21.760: E/AndroidRuntime(4255): at com.example.hematoma.EditorActivity.fce(Native Method)
04-30 13:36:21.760: E/AndroidRuntime(4255): at com.example.hematoma.EditorActivity$3.onClick(EditorActivity.java:166)
04-30 13:36:21.760: E/AndroidRuntime(4255): at android.view.View.performClick(View.java:3110)
04-30 13:36:21.760: E/AndroidRuntime(4255): at android.view.View$PerformClick.run(View.java:11934)
04-30 13:36:21.760: E/AndroidRuntime(4255): at android.os.Handler.handleCallback(Handler.java:587)
04-30 13:36:21.760: E/AndroidRuntime(4255): at android.os.Handler.dispatchMessage(Handler.java:92)
04-30 13:36:21.760: E/AndroidRuntime(4255): at android.os.Looper.loop(Looper.java:132)
04-30 13:36:21.760: E/AndroidRuntime(4255): at android.app.ActivityThread.main(ActivityThread.java:4123)
04-30 13:36:21.760: E/AndroidRuntime(4255): at java.lang.reflect.Method.invokeNative(Native Method)
04-30 13:36:21.760: E/AndroidRuntime(4255): at java.lang.reflect.Method.invoke(Method.java:491)
04-30 13:36:21.760: E/AndroidRuntime(4255): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
04-30 13:36:21.760: E/AndroidRuntime(4255): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
04-30 13:36:21.760: E/AndroidRuntime(4255): at dalvik.system.NativeStart.main(Native Method)
Solution
After few days of hopelessness :D I solve my problem. The issue was that $(OPENCV_INSTALL_MODULES) should be equal. At the line OPENCV_INSTALL_MODULES:=on in my Android.mk file.
I overrided OPENCV_INSTALL_MODULES:=on
to
OPENCV_INSTALL_MODULES=on
and now it works.... Perhaps it might help to someone else too :)
Answered By - User
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.