Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Java with NDK Android?

I am assuming that using the OpenCV code here: http://github.com/billmccord/OpenCV-Android#readme is the best way to use OpenCV on Android, with the NDK.

I am still stuck as to how I get from the C definitions of functions to the ones I declare in OpenCV.java in my Android project

cvFindContours( void*  img,  CvMemStorage*  storage, 
                CvSeq**  firstContour, int  cntHeaderSize, 
                int  mode, 
                int  method, CvPoint offset ) --> findContours(int[] 
data, int w, int h) ) 

Any help/pointers appreciated, even where to start to figure this out. I currently want to use cvHoughCircles, cvHoughCircles(CvArr* image, void* circle_storage, int method, double dp, double min_dist, double param1 = 100, double param2 = 300, int min_radius = 0, int max_radius = 0};

How do I write this in java with ndk for android?

like image 696
cjayant Avatar asked Feb 09 '10 19:02

cjayant


People also ask

What is NDK Java?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.

What compiler does Android NDK use?

Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++.

Which is better NDK or sdk?

It is important to mention that some Android Apps use NDK to achieve a specific functionality. That makes NDK and SDK somehow complementary in some cases. However, Android still recommends to only used NDK if you really need to.

What is difference between Android NDK and sdk?

Android provides Native Development Kit (NDK) to support native development in C/C++, besides the Android Software Development Kit (Android SDK) which supports Java. [TODO] more.


2 Answers

Does your app require the C interface? OpenCV actually considers it deprecated / done with, the new API is C++. A port of this interface and sample calibration app are here: http://code.google.com/p/android-opencv/

It took me a while to get sold on the new C++, but I had to admit it was nice to not have to do cvReleaseMat() and go back and forth between IplImage and CvMat all the time. Opencv 2.1 doc: http://opencv.willowgarage.com/documentation/cpp/index.html

like image 155
peter karasev Avatar answered Oct 28 '22 09:10

peter karasev


Look at the Android samples within the ndk (hello-jni). They are in the apps directory of the NDK. They show how to import the library and call native methods. On C side of things you have to give your methods the proper jni naming conventions Java_...fully qualified java class name, make methods external and also include to make them accessable.

Also the docs directory of the NDK has all the documentation on building and running native code.

like image 36
Patrick Kafka Avatar answered Oct 28 '22 11:10

Patrick Kafka