简体   繁体   中英

C++ and Java Communication for image processing application

I have to build a software for image processing. I was using java to display images and c++ for functionality of application. It is obvious that images will be send from C++ to java and vice versa. I am confused for which approach to choose for communicating c++ and java. I studied and did lot of research and finally found 3 approach:

  1. JNI(java native interface)

  2. Pipes

  3. Socket. Which approach will be better to choose?? I have to handle HD images upto 10MB. Please help me guys.

If the c++ application could be installed and accessed as a command line application (Eg: FFMpeg, MLT etc.,), follow these ...

  1. Access the c++ application with runtime process execution Runtime.exec() in Java. This will save you a lot of effort than other options.
  2. Queue implementation to streamline the executions in a clustered processing environment (when your traffic is high)
  3. Error handling/logging of runtime process execution

Reference : Invoking via command line versus JNI

I also work on same issue. As a professional manner, using JNI for calling a C++ DLL from java is the best way according to my last benchmark test. JNA is another way but it is slower and has less opportunity for some functionality such as two side object mapping and pass-bye-reference issues. 10 MB is also small amount for it, I tried it with 2 GB images and JNI succeeded that large file without any problem(never concern about 10 MB file, JNI gives you more). You can compose a C++ DLL for your functionalities and you can implement a java interface to call them with JNI. A new alternative proposed to do this which is called Panama Project. I think JNI is the best way up to Panama finish date, we will see Panama will be best or JNI will hold current position.

JNI is an absolute must for performance reasons. However, it is quite inconvenient to use, so this is why I have created tools on top of JNI to facilitate the use of JNI with C++: JavaCV and JavaCPP . I developed them initially for my own purposes of image processing in Java, so they should be a perfect fit for your own purposes. Check out the demo video of ProCamTracker , the application I built with them. It works great in real time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM