I am trying to implement a face recognizer in java. I got this code example and made changes to fit my requirements on how the system should behave. It works but then when I have images of the same person in different light intensities its efficiency drops. I read that there is a library inserted in openCV for faceRecognizer but then its samples are implemented in c++. Is there any way i can use this library to code in java? and also if we can use it then will it increase the efficiency of the code?
Please do provide some help on this. Stuck on it badly...
You can create a C++ dll for java. You should write a wrapper class (in C++) which uses your C++ codes. Function definitions of the wrapper class should use JNI. This link here should be helpful (it was for me). After you implement the wrapper class, export it as a dll.
Just Use java cv so that you can use all c++ function in java.
Download all javacv jar files and try to install javacv to your system
Just look through how to setup javacv in your system.
I think this should do the magic in java
FaceRecognizer model=createFisherFaceRecognizer();
model.train(images,label);
For prediction
Int id=model.predict(img);
Related
I am facing a critical issue trying to export my opencv project to android.
Since all of my code is in opencv (C++ version) under visual studio 2013, i started off looking into JNI. I ended up realizing that JNI works good when we export C stuff as name mangling is turned off. Does this affect my C++ code? I think it should as name mangling has to be there for C++ class functions.
Then I found out about JavaCPP. This seemed more promising but the extra overhead its Pointer logic seems strange to get my head around and extra build steps to create .so files.
And finally, read about Visualgdb. Though seems to be in trial, but with my liking for Visual studio, looks reasonable.
Can someone guide my which way I have to follow to translate/bind my code in android so that I can export my c++ classes? Does plain JNI have a real issue with C++ code and no problems with C? OR do I go for JavaCPP or visualgdb?
You valuable comments will be highly appreciated.
Thanks
AFAIK you can use JNI on your c++ code, I'm using it. But you should only use JNI if you want to write all your code in c++ and want java to use that exact c++ code in java side. And for that you should export all functions in your public API. And I must say, passing through custom objects such as Mat, Rect, etc is not a very easy problem, also debugging is not also straight forward. I suggest you to use OpenCV Java and port your code to Java.
Good luck!
I have an image processing code in matlab containing its inbuilt functions like graythresh(), bwareaopen(),etc. I need to make that code processable on a smartphone(preferably with android os).The code also contains methods of image segmentation like Otsu. It would be of great help if you could suggest me the best and easy way to do that. I know elementary Java, but I do not know much about android programming.
You have several options:
The best things to do is to port your code in java or port your code to use openCV.
Use Matlab coder to generate C code. This C code doesn't require the MCR, and could be compiled to run directly on Android
You could try using the very handy Octave for Android:
https://play.google.com/store/apps/details?id=com.octave&hl=en
It may not have all of the functions you need (as it is Octave, and a port) but it will be a good start.
I want to develop a small Java program using some input like the pen of a Wacom graphictablet and found only the very active JPen project but are there some more possible alternatives without JNI or JNA (without any additional needed dll files), a pure Java implementation?
You can take a look at JTablet. From another SO thread.
It seems JPen moved to GitHub and this might be the best solution at the moment.
The other alternative solutions are not developed and maintained anymore.
https://github.com/nicarran/jpen
I have a java code and created a jar file.
I need to create an Qt application. Can I use this code in that application?
Please help me how can i use that jar file.
Thanks,
Nagaraju.
You could take a look at the capabilities of GCC/GCJ (see http://gcc.gnu.org/ ). IF it's a good idea is a whole other story, and depends on what you have, and what you're trying to accomplish. It should be doable to link SO's created with GCJ in QT applications, but I seriously wonder if you are not better off using either C++ or Java, but not mixing them
If your Java code takes input from stdin or some file and writes output to stdout or some file, then the easiest way is to fork java to run that jar, and parse the output in your Qt code.
Things other than that, you'll need to be a bit specific. Something like "my Java code does painting the screen".
My advice is to use SWT or Swing.
You can use gcj gcj to compile the java code to library and simply call the functions of the java code from your C code.
Yes, you can use your jar file in your Qt application. I've done exactly this myself.
One way is to use the JNI Invocation API. This is part of the Java Native Interface (JNI), which makes it feasible but not pleasant to access Java APIs from C++.
A much more pleasant approach is to use CodeMesh JunC++ion, which wraps the Java APIs in C++ classes. This is a great product, if you can afford it.
If you have very little Java code, it may be easier to port it to C++.
I am doing a project in java which has the function to add files in database, and i want to use winapi functions to select files.
How would i do that?
By far the easiest way is by using Java JNA, it already has translation from stcalls in.
You can find a basic tutorial for it (with Winapi example no less) on JavaWorld.
You could also use JNI, but JNI requires you to use specially built header files for interfacing and it's all in all harder to maintain and use. It's slightly faster in some cases though.
You want Java Native Interface - this tutorial shows you how to implement your own but you could easily just point to WinAPI functions - http://java.sun.com/docs/books/jni/download/jni.pdf
Here's an example I found with a quick Google - not the neatest webpage but still demonstrates the concept well http://edn.embarcadero.com/article/20679
I strongly advise JACOB (Java COM Bridge) for using COM interfaces.
http://sourceforge.net/projects/jacob-project/
I wrote an app for getting song infos from Amazon Web Services. Its a nice library to have.