0

I'm working on an OpenCV project that is currently prototyped in python, but I want to make work in Android.

I thought it would be better to start with straight java and then move that to Android, but OpenCV for java doesn't seem to be as fully implemented as it is for Python and C++ (for example it doesn't have imshow). So now I'm not sure how easy the conversion from Python to Java will be.

Since Python to C++ has been relatively easy in the past for me when working with OpenCV, it got me thinking of other options. I see that you can run pre-compiled C++ code in Android, so that may be an option. The issue that I see is that I'm not sure how well I can pass the data I need. What sorts of limitations are there when communicating between Android Java and the pre-compiled C++? And is the pre-compiled C++ allowed access to the filesystem, so it can read images?

Bill
  • 698
  • 1
  • 5
  • 22

1 Answers1

0

You can pass any data that java supports. Obviously you can't pass C++ classes as is (though you can pass a pointer as long, keep in Java and then pass it back to C++ where it can be used again).

On C++ side, through JNI APIs you can do everything you can do with Java code. However, it will require an extra work and clear understanding about thread binding, JNI context and JNI/Java memory management.

On Java side, you can pass to C functions strings, primitive types (easy) or complex types and then use JNI to access fields, call methods, throw exceptions and so on.

There are some pitfalls about memory management, if you allocate Java heap from inside C++/JNI, read carefully about allocations, lifecycle and reference types.

Android-specific, you also may want to read some JNI Tips

Android native can access IO and filesystem at least with the same functionality as regular Android Java apk. You may look here for an example and a discussion File Operations in Android NDK

Community
  • 1
  • 1
Coder
  • 51
  • 4