I would like to use the facedetection in opencv cpp to use it in an android app. I have compiled jni successfully. But I wonder how would i use the haarcascades. I can store in sdcard and read it from there. Is there any other way i can use the xml files directly from the project?
There is a c++ example called facedetect coming with the opencv superpack. I'm running OpenCV-2.3.1 myself and it's located in this folder: ../opencv-2.3.1/samples/c/
The sample uses haarcascades and this might be your best bet for facedetection. If you can use the Android NDK with proper JNI calls from a .cpp file then you shouldn't have any problems to use this sample.
I'm working on a similar thing myself but haven't tried it myself yet. Should be implementing the thing somewhere next week but can't guarantee it. Let me know if this works out for you
Related
I am not sure, if this is the right place to ask, but I am curious, if there are any Android NDK examples (apks), on how to read a file with Java and pass it over to C/ C++ using JNI.
Currently I am trying to read pdf or office files (e.g. docx) with C/ C++ and I am trying to understand the concept behind it.
Maybe there are some full apk examples or just some snippets, with which I could extend the hello-jni/ hello-jnicallback examples.
I already found the android ndk samples site https://github.com/android/ndk-samples, but there seems to be no example on how to simply read files.
Thank you for your help.
We have a c++ project on android, which will be built into .a then release the .a to our users.
The problem is, we have many resource files, and these resources' path is necessary because some 3rd-party libs need them.
The limitation on android is: if we want to put a file in Android APK, we must package it in res or assets and it is not single file any more, so how can we organize our resources?
Our plan is to require our users to package our resources in APK's Assets, then we can extract them to other folder, but it's not user-friendly, do you have any better idea?
thanks
C++ android project, it sounds me weird, may be, you would like to say that you have c++ arm crosscompiled static library .a which it is able to load in an Android project.
I guess you want to share a library which uses many resources, and you need the elegant way to distribute.
Try to create a .jar file which it has native functions:
Firstly create your core class exporting functions and define your
public native functions to JNI.
Don't use activities, if you need to access to activity context, pass
through parameters.
If you want to use resources, your layouts will not be able to use in
your parent android project.
You can use drawable files and you can add layout files programatically (with activity context).
If you are going to use some resources such as xml config files, put
in the res/raw folder or in assets folder.
If you have good Java and JNI skills, this task is not so difficult.
Hope the advices help you.
Cheers.
I think you need to develope a NativeActivity. If you follow the proper documentation, you could create a working app to do whatever you want. If you want to open assets, process, you can do it, and launch this app from another one.
If you really want a single library to be used, Just do it in c/cpp, and initialize it with a JNI function call providing the asset path and aassetmanager, and use the AAssetManager object in native. You will need to include jni.h, of course you will need to crosscompile the library using the NDK toolchain, and gradle or cmake toolchain scripts.
I want to list folders and files inside Resources folder from android and ios. I've been able to do so by 'opendir' and 'readdir' from 'dirent.h' but only in ios emulator. It doesn't work in android.
Did anyone face such problem?
Thanks.
AFAIK, this can't be done on Android using only C++. Since you already have the iOS part figured out, you shuould wrap the iOS specific code (#includes too) in
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
...
#endif
The same will aply for Android only code (`CC_PLATFORM_ANDROID') - to achieve what you want you have to write a JNI call in order to call a Java function from C++. Assuming that you want to just dump this data to a log, everything should be pretty straightforward. I don't have a link at hand, but there was an extensive topic about opening URLs which coverd the JNI tutorial and it shouldn't be hard to find.
One way could be to mantain a file containing a list of all the files in the resource directory along with their hierarchy.
For example, say you have a directory hirearchy as:
Resources/
folder1/
file1.jpeg
file2.jpeg
folder2/
file1.jpeg
file2.jpeg
Then you can mantain a file containing the paths as:
in resource_paths.txt
folder1/file1.jpeg
folder1/file2.jpeg
folder2/file1.jpeg
folder2/file2.jpeg
Then search in the file for list of directories/files :)
I have recently begun using the Android NDK and I have successfully implemented a few simple Android apps. I need to detect objects (squares and rectangles) from an image. My research has shown me that OpenCV is the solution for this. This is the algorithm I use to detect a square from the image.
However, I am unclear as to how should I use the squares.cpp file in my code. The OpenCV samples show how to use the cpp files in JNI format. Do I need to convert the squares.cpp file to JNI or would there be another feasible solution?
Thanks. All suggestions and feedback are welcome.
You don't have to convert the squares.cpp file to JNI.
From your Java code, you will call a JNI function (as I suppose you did in the "few simple Android apps" you have implemented) that will then call the functions in squares.cpp.
In other words, you basically only need one call to a JNI function from Java, and once you are in the C++ code, you can code in C++ as usual.
How can I get reach to the native methods called from Java side in Android? My problem is specifically related to AudioRecord class in Android Media package. I read the source code of AudioRecord.java. I found out that most of the jobs is performed by native methods, such as:
native_setup(...), native_start(...), native_stop(...), native_read_in_byte_array(...), native_read_in_direct_buffer(...)
I downloaded Android source code but I could not reach these methods. And I don't actually know the way to reach them. I seek for these methods in libraries I found in source code directories, but I couldn't success. If anybody may have an idea, I would be appreciative to hear. Thanks...
I think I found them. After using the Linux command
grep -r "native_read_in_direct_buffer" ./ANDROID_SOURCE/.*
I found the corresponding cpp files.
AudioRecord.cpp is located in: ~/ANDROID_SOURCE/frameworks/av/media/libmedia/ directory,
android_media_AudioRecord.cpp is located in ~/ANDROID_SOURCE/frameworks/base/core/jni directory.
I wanted to share it as a reference to other possible programmers willing to reach the same/similar source files.