Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Wednesday, April 25, 2012

jni getobjectclass function error "SIGSEGV"

Here is my code :

    midMain = env->GetStaticMethodID( clsMTT, "TagCalculation", "()LReturnTags;");
        tagInfo = env->CallStaticObjectMethod(clsMTT, midMain, NULL);
        clsR = env->GetObjectClass(tagInfo);





When I run this program, I get the following the "SIGSEGV" error caused by GetObjectClass function.

The reason is the function "TagCalculation" returned a empty object "tagInfo" when I run "CallStaticObjectMethod".
Therefore, the GetObjectClass tries to find a class from an empty object. This will be wrong.
The solution is very simple: I change the function "TagCalculation" to always return a real object, which is not empty.
Then, the error gone.

Wednesday, August 10, 2011

JAVACV: no jniopencv_core in java.library.path

To solve it, adding following lines to ~/.bashrc:
#For JavaCv
export CLASSPATH=$CLASSPATH:~/Src/javacv/javacv-bin/javacpp.jar:~/Src/javacv/javacv-bin/javacv.jar:~/Src/javacv/javacv-bin/javacv-linux-x86.jar

The key solution is the javacv-linux-x86.jar. If you are using 64bits windows, then you have to choose javacv-windows-x86_64.jar.

Tuesday, June 14, 2011

Run April Toolkit ( including April tags) in C/C++ environment (call java classes from C/C++)

This is one example application: run April Toolkit (April tags) in C/C++. It requires the JNI to call Java functions in C/C++. You could download the source file from HERE.

The original April toolkit is working in the Java environment. However, my project needs C/C++, so how to wrap Java into C/C++ project becomes one problem.
After a few days work, I finally get a solution to solve this.

There are two subfolders in this application :
1, One is "java" folder. It includes Java source file "myTagTest.java", which is a simpler version of "TagTest.java" in the AprilToolkit. This program reads the frames from webcam, detect the april tags and calculate the relative pose matrix. That's all, so it's simpler and easier to understand than the original one.
2. The other one is "cpp" folder. It includes the C source file "ctest.cpp" and a "Makefile". The main architecture of the ctest.cpp is first launching the JVM, then finding the java class and java function, finally running the function.

How to run it (for Linux):
1. Download and install the April toolkits from:
http://april.eecs.umich.edu/wiki/index.php/April_Tags

2. Download the source file of my application from my website:
https://sites.google.com/site/guoliangliu2010/opensouce

3. In the java folder:
$ javac mytagTest.java

4. In the cpp folder:
$ make ctest
$ ./ctest

P.S.
I need thanks the engineer Ahmad Jalil Qarshi. He gives a nice introduction about how to call Java classes in C/C++, which can be found in the following link:
http://www.codeproject.com/KB/cpp/CJniJava.aspx

Wednesday, June 8, 2011

JavaCV for webcam

Now I start to conquer Java for robotic stuffs.
I am used to use opencv, so I find Javacv is a nice interface to wrap opencv.
After download and install the javacv, I try to run a sample: "MotionDetector.java".
But it gives me some errors like:
HIGHGUI ERROR V4L2

The solution is commenting following lines in the OpenCVFrameGrabber.java:
cvSetCaptureProperty(capture, CV_CAP_PROP_CONVERT_RGB, colorMode == ColorMode.BGR ? 1 : 0);
and
return_image.timestamp(Math.round(cvGetCaptureProperty(capture, CV_CAP_PROP_POS_MSEC)*1000));

Now it works, but it return BGR image instead the RGB image.
I don't think it's a good idea to use CV_CAP_PROP_CONVERT_RGB in the above line, because the Opencv users are used to use BGR. If they don't check the source, they will never know the function "grab()" return a RGB image.

Now recompile it using command "ant" and copy the generated ./dist/javacv.jar to the CLASSPATH.

Thursday, January 14, 2010

Linux Matlab and German keyboard

The new linux version matlab (e.g. R2008, R2009) can not work with german keyboard, it works following the english keyboard map.
I have tried a lot method and it still can not work until today (great day)!
When I run matlab, it show me a error message:
"
********************************libjvm.so
[0xb31ab8ec]
Locking assertion failure. Backtrace:"

It can not lock the java. The reason is it find the wrong one. The solution is run a command shell and type:
"export MATLAB_JAVA=/usr/lib/jvm/java-6-sun-1.6.0.17/jre
"

Now it correctly show the character of the german keyboard. Of course, you may have different version of JAVA and install directory that you must figure out, and use yours instead mine. You also can add this command to your "~/.bashrc" file, so that every time you login, you donot have to run this command manually.


But the symbols "^" and "~" still can not work in this Linux. I test this method on Windows Vista, both symbols can work.
On Vista, open a command prompt, then use command setx to set the variable MATLAB_JAVA:
"setx "MATLAB_JAVA" "C:\*************""