making matlab code android compatible - java

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.

Related

Is there a way to call a Java class from a Visual Studio Windows Forms Application?

I mainly program in Java, but I often do GUI things on Visual Studio. I have written a program in Java that is fairly comprehensive and long, and I do not know how to rewrite it in Visual Basic. Is there any way I can call methods or create objects in Visual Basic that is based off of a Java class, or are there other ways I can implement or import Java snippets into Visual Studio?
I saw something like this, and I'm not sure how it works:
Private Sub Command1_Click()
Set x = CreateObject("MyTest")
MsgBox x.myfunction(500, 500)
End Sub
I saw some information on "bridges," but my goal is to do things just on my PC and not on the cloud.
Realistically, you're probably going to have to spend a lot of time working with JNI and P/Invoke (or whatever .NET's native interfaces are these days) to get Java code talking natively with managed code on .NET in the same process. You're better off just wrapping your Java code with Spring Boot and calling it as a service.

Exporting C++ project to Android - JNI/JavaCPP/Visualgdb

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!

How to use the FaceRecognizer library created in openCV from Java?

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);

Android and Java's JNI

I'm starting to learn java's JNI to use with an android device.
As I read somewhere, you must have some "glue" for the C++ part in order to be loaded through JNI.
My question is: Is it posible to have a run() function in C with the glue for JNI having that running the real app and having java only for the entry point?
Because I don't know if when invoking that run() function through JNI it may cause problems if that function calls another functions and so on.
Thanks for the tip!
EDIT: I want to code in C++ using ndk and trying to avoid coding in java. thus, I wanted to know if a) if I can compile and run in native with ndk or b) if i can use java only to invoke my app, example: calling woth jni something like app->run() and let it do all stuff instead of java. then, java will act only as an entry point.
If you want to develop for Android in C/C++ (no Java) AND you target newer devices (Gingerbread, android-9 app platform onwards) consider using NativeActivity.
See http://developer.android.com/reference/android/app/NativeActivity.html and folder inside NDK package $NDK/docs/NATIVE-ACTIVITY.HTML together with the sample code $NDK/samples/native-activity.
Good luck!
I made a step-by-step howto in the following post: How to create dll using android You can read it and put questions if you don't understand something.

Convert Java jar file in to cpp

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++.

Categories