Native OpenCV face detection error - android

I'm new on developing a native code for android application.
Actually I'm going to test some native OpenCV samples for android. I'm using Eclipse. I found a few errors upon compiling the face detection example.
I could correct most of the errors by  following this tutorial
And
I defined my environment variable NDK-root
activation of some configs on Android.mk
The console result is that the libraries .so are correctly built, as the following :
[armeabi-v7a] Install : libdetection_based_tracker.so =>
libs/armeabi-v7a/libdetection_based_tracker.so [armeabi-v7a] Install
: libnative_camera_r2.2.0.so =>
libs/armeabi-v7a/libnative_camera_r2.2.0.so [armeabi-v7a] Install
: libnative_camera_r2.3.3.so =>
libs/armeabi-v7a/libnative_camera_r2.3.3.so [armeabi-v7a] Install
: libnative_camera_r3.0.1.so =>
libs/armeabi-v7a/libnative_camera_r3.0.1.so [armeabi-v7a] Install
: libnative_camera_r4.0.0.so =>
libs/armeabi-v7a/libnative_camera_r4.0.0.so [armeabi-v7a] Install
: libnative_camera_r4.0.3.so =>
libs/armeabi-v7a/libnative_camera_r4.0.3.so [armeabi-v7a] Install
: libnative_camera_r4.1.1.so =>
libs/armeabi-v7a/libnative_camera_r4.1.1.so [armeabi-v7a] Install
: libnative_camera_r4.2.0.so =>
libs/armeabi-v7a/libnative_camera_r4.2.0.so [armeabi-v7a] Install
: libopencv_java.so => libs/armeabi-v7a/libopencv_java.so
But when running the application, a syntaxic error raised in the jni file: « DetectionBasedTracker_jni.cpp », at two places :
1- result = (jlong)new DetectionBasedTracker(stdFileName, DetectorParams);
error = type 'DetectionBasedTracker'could not be resolved
2- ((DetectionBasedTracker*)thiz)->getObjects(RectFaces);
error : Invalide arguments 'Candidates are : void getObjects(?&)'
Please see the attached images
I don't understand why I got these errors, since i never touched the original code ?
Any idea to correct these bugs ?

DetectionBasedTracker_jni.h is missing from your project. It is included in general, I don't know why you don't have it. It may cause your errors, but its just a tip.
timurDroid
In Eclipse i always have like this error, but after close cpp file and
restart IDE Eclipse, Apllication successfull run. Dont know, why it..
I believe the anomaly you are talking about may be a different issue, because in that case you have a Lot of error messages containing could not be resolved, correct me if you only have that one (a few, not all). For me if I open these jni files "everything cannot be resolved" due to (I'm just guessing) prebuild-linking eclipse bugish issues.

Finally!!. I solved this problem by recreating a new project, then imported the src files into.
Now it works fin!

Related

Issue in Linking a C Library compiled with CMake in Android.

I am building a daemon on Android Platform. For which I have cross compiled the existing code, which is present in Linux to Android. Please consider my below 2 cases -
I cross compile the code using Cmake with Android NDK-15 and push manually to the board on which Android Code is available. The path in which we push is /system/lib. Then if I try to execute my daemon (which is also pushed manually to /system/bin ) everything works fine.
But,
2 The cross compiled library have been pushed into the AOSP code by writing an Android.mk file written in vendor specific folder. I have used BUILD_PREBUILTS method and was successfully able to push the libraries to /system/lib. Now, when I try to execute my application (Compiled with CMake ) I get a linker error.
Below is the error which I get ( Reference Example ) -
Below is the folder structure -
Total Number of folders - 3
a. abc folder which produces output libabc.so and links to libdef.so and
libghi.so
b. def folder which produces output libdef.so
c. ghi folder which produces output libghi.so
When I push all the 3 libraries (libabc.so, libdef.so, libghi.so ) directly in /system/lib and my executable (drive_test) which links all the 3 libraries, I have no issue. But, when I push it along with AOSP build I get the following error on execution of the executable (drive_test) -
a. Unable to link ../abc/def.so file.
I am unable to debug how to solve this linker issue. I am not getting whether it is because of CMake (or) any other issue.
If you're trying to make a system daemon (something that goes in /system/bin), don't use the NDK. Just use the AOSP build system.
In mydaemon/Android.bp (make sure to add this path to the root Android.bp file):
cc_library {
name: "libmylib",
srcs: ["mylib.cpp"],
}
cc_binary {
name: "mydaemon",
srcs: ["mydaemon.cpp"],
shared_libs: ["libmylib"],
}
The build system will deal with getting libraries and binaries into the right place for you.

Cross compiling c program with openssl for Android

I am facing the following issue when trying to compile a c program using openssl for android x-86. I set up the environment variables as follows using the following script:
setenv-android.sh
After running the script I have the following environment.
./setenv-android_x86.sh
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
Error: FIPS_SIG does not specify incore module. Please edit this script.
ANDROID_NDK_ROOT: /opt/android-ndk-r9d-x86
ANDROID_ARCH: arch-x86
ANDROID_EABI: x86-4.6
ANDROID_API: android-18
ANDROID_SYSROOT: /opt/android-ndk-r9d-x86/platforms/android-18/arch-x86
ANDROID_TOOLCHAIN: /opt/android-ndk-r9d-x86/toolchains/x86-4.6/prebuilt/darwin-x86_64/bin
FIPS_SIG:
CROSS_COMPILE: i686-linux-android-
ANDROID_DEV: /opt/android-ndk-r9d-x86/platforms/android-18/arch-x86/usr
However when trying to compile with the following command I get the following error:
pwd
/opt/android-ndk-r9d-x86/bin
./i686-linux-android-gcc Test.c -o test -lcrypto
fatal error: openssl/conf.h: No such file or directory
When I locate for the openssl/conf.h I see the file is available in many places:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/openssl/conf.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/openssl/conf.h
/data/local/arm/ssl/include/openssl/conf.h
/data/local/ssl/include/openssl/conf.h
/openssl/include/openssl/conf.h
/openssl-1.0.1e/include/openssl/conf.h
/openssl-1.0.1g/include/openssl/conf.h
/opt/local/include/openssl/conf.h
/usr/include/openssl/conf.h
/usr/local/include/openssl/conf.h
/usr/local/ssl/android-14/include/openssl/conf.h
/usr/local/ssl/android-18/include/openssl/conf.h
/usr/local/ssl/android-18-x86/include/openssl/conf.h
/usr/local/ssl/include/openssl/conf.h
I think the proper path is this:
/usr/local/ssl/android-18-x86/include/openssl/conf.h
I tried with the -L option but with no luck.
-L/usr/local/ssl/android-18-x86/include/
Can anybody please explain how to setup the path properly to solve this issue. (finally there is no issue with the C code as it compiles properly with gcc)
You are compiling your code using the Android NDK, which creates a "virtual" compiling environment by placing everything you need to compile for android into the ${ANDROID_SYSROOT} directory.
Those directories you listed are outside that sysroot, and therefore are not available to the build system, hence the errors. You must install OpenSSL for Android and putting the resulting headers and binaries there. You might follow this guide to assist you in that.

Eclipse ADT "undefined reference to (custom class)", but works fine in Xcode (using Cocos2dx)

I have a project that's fully functional in Xcode but not compiling in Eclipse ADT. I have successfully compiled and run android applications in the past, but this is my first time to create a custom class. To replicate the issue:
I create a new project, then add the following 2 files:
//Enemy.cpp
#include "Enemy.h"
USING_NS_CC;
bool Enemy::init()
{
if(!Layer::init())
return false;
return true;
}
//Enemy.h
#ifndef __ColorMirror__Enemy__
#define __ColorMirror__Enemy__
#include <iostream>
#include "cocos2d.h"
USING_NS_CC;
class Enemy : public cocos2d::Layer{
public:
CREATE_FUNC(Enemy);
virtual bool init();
};
#endif
I am able to see them in Eclipse in the list of classes.
Then I create a new enemy in HelloWorldScene.cpp as follows:
Enemy *newEnemy = Enemy::create();
This compiles and runs as expected in Xcode, but when I run build_native.py I get the following errors:
jni/../../Classes/Enemy.h:19: error: undefined reference to 'Enemy::init()'
jni/../../Classes/Enemy.h:19: error: undefined reference to 'vtable for Enemy'
Checking in the jni/../../Classes file, I am able to find Enemy.h and Enemy.cpp.
I have seen several explanations for fixes in other versions of Eclipse, and the suggestion it's a linker error, but I haven't figured out how to fix it in ADT.
Thanks!
So I'm not entirely sure which of these steps fixed the problem, and it may very well have been multiple issues, but here's what I did:
1) Added Enemy.cpp into Android.mk as follows:
Browse to game folder /proj.android/jni and open Android.mk
Open with TextEdit
Below the AppDelegate.cpp in LOCAL_SRC_FILES: added this:
../../Classes/Enemy.cpp \
Save
(still didn't work, so I took it out)
2) Changed workspace for Eclipse (which is specified on opening eclipse) and deleted old workspace
3) Downloaded and set up newest ADT package (Eclipse JUNO)
4) Upgraded Cocos2d-x from 3.1 to 3.2
(still didn't work)
5) Added Enemy.cpp to Android.mk again
Upon completing all those steps, everything works great and compiles as before.
Thanks to Wez Sie Tato for confirming that Enemy.cpp did in fact need to be added to Android.mk... Based on some comments I've seen elsewhere, it appears that my ADT package may have gotten damaged somehow, in conjunction with not having the proper line in Android.mk

Building OpenCV app with JNI in Eclipse

I've got a problem when building android applications with OpenCV and JNI part in Eclipse.
The problem is than ndk-build runs normally for the project, but Eclipse shows errors (usually irrelevant to the code).
For example, I'm building one of the OpenCV4Android samples:
boris#boris-ubuntu:~/src/OpenCV-2.4.3-android-sdk/samples/tutorial-3-native$ ndk-build
Install : libnative_camera_r2.2.0.so => libs/armeabi-v7a/libnative_camera_r2.2.0.so
Install : libnative_camera_r2.3.3.so => libs/armeabi-v7a/libnative_camera_r2.3.3.so
Install : libnative_camera_r3.0.1.so => libs/armeabi-v7a/libnative_camera_r3.0.1.so
Install : libnative_camera_r4.0.0.so => libs/armeabi-v7a/libnative_camera_r4.0.0.so
Install : libnative_camera_r4.0.3.so => libs/armeabi-v7a/libnative_camera_r4.0.3.so
Install : libnative_camera_r4.1.1.so => libs/armeabi-v7a/libnative_camera_r4.1.1.so
Install : libnative_sample.so => libs/armeabi-v7a/libnative_sample.so
Install : libopencv_java.so => libs/armeabi-v7a/libopencv_java.so
It runs normally, but Eclipse shows errors:
'size_t' is ambiguous '
Candidates are:
Field 'pt' could not be resolved
Field 'pt' could not be resolved
Field 'x' could not be resolved
Field 'y' could not be resolved
Invalid arguments '
Candidates are:
void detect(const cv::Mat &, ? &, const cv::Mat &)
void detect(const ? &, ? &, const ? &)
The type 'cv::FastFeatureDetector' must implement the inherited pure virtual method 'cv::FeatureDetector::detectImpl'
And other error like this one in other projects. And also, the Eclipse intellisense (or how is it called properly :) is not working on .cpp files.
I've tried to clean the projects, delete the obj and lib folders, but no effect.
My system is ubuntu 12.04, OpenCV version is 2.4.3.
Thanks for any help!
Had same problem with you on ubuntu 12.04, OpenCV version is 2.4.3. exactly on the same example and I am using the eclipse-android bundle.
Here's what I did:
Update the NDK plugin using google repo, It is already installed but it can be updated.
Then I changed size_t to int and added a temp variable instead of going straight as the example goes. Here's the code:
Mat* pMatGr=(Mat*)addrGray;
Mat* pMatRgb=(Mat*)addrRgba;
vector<KeyPoint> v;
FastFeatureDetector detector(50);
detector.detect(*pMatGr, v);
for( int i = 0; i < v.size(); i++ )
{
KeyPoint tK = v[i];
circle(*pMatRgb, Point(tK.pt.x, tK.pt.y ), 10, Scalar(255,0,0,255));
}
It really is a weird bug, my guess is that it has something to do with eclipse debug mechanism not working properly.
Yea very strange bug. Am on Ubuntu 12.04 and OpenCV 2.4.5.
I got the same bug on 'OpenCV Tutorial 2 - Mixed Processing'
Managed to fix it without reinstalling Eclipse or NDK. Just deleted the sample project, then imported it again. Works fine now.

How to use NDK?

I have to edit a project using some C++ stuff (commons-codec-1.4) to read a SVG file. If I comment out the SVG reference it works fine but I have to run with it. It originally compiled with NDK. I downloaded NDK but don't know how to attach with this project.
build.log file in jni folder says
Android NDK: WARNING: Unsupported source file extensions in /cygdrive/c/work/Android/Source/yprintit-android/jni/Android.mk for module svgandroid
Android NDK: libpng/png.h libpng/pngconf.h libpng/pngpriv.h libsvg/svg.h libsvg/svgint.h libsvg/svg_ascii.h libsvg/svg_version.h libsvg/svg_hash.h libsvg-android/svg-android.h libsvg-android/svg-android-internal.h
Compile thumb : svgandroid <= /cygdrive/c/work/Android/Source/yprintit-android/jni/datauri/base64.c
SharedLibrary : libsvgandroid.so
Install : libsvgandroid.so => /cygdrive/c/work/Android/Source/yprintit-android/libs/armeabi

Categories

Resources