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

Friday, June 10, 2011

Remove ^M in the VIM or GVIM

The ^M is the \r in the file. To remove these strange things, you could do replace \r by space. Very simple.

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.

Tuesday, June 7, 2011

Type D in the vncviewer

I got a problem when I was using vncviewer: couldn't type d in the terminal or other windows.
The solution is:
1. Go to System->Preference->Keyboard shortcuts
2. Find the item Hide all normal windows and set focus to the desktop
3. Type Alt+D to change this hot key
4. vncserver -kill :1 which kills the current server
5. restart the vncviewer.

Problem Solved

Friday, May 27, 2011

To use cvCvtColor

Be careful to use CV_BGR2HSV, the detail of the manual shows:
// In case of 8-bit and 16-bit images
// R, G and B are converted to floating-point format and scaled to fit 0..1 range

V <- max(R,G,B)
S <- (V-min(R,G,B))/V if V≠0, 0 otherwise

(G - B)*60/S, if V=R
H <- 180+(B - R)*60/S, if V=G
240+(R - G)*60/S, if V=B

if H<0 then H<-H+360

On output 0≤V≤1, 0≤S≤1, 0≤H≤360.
The values are then converted to the destination data type:
8-bit images:
V <- V*255, S <- S*255, H <- H/2 (to fit to 0..255)
16-bit images (currently not supported):
V <- V*65535, S <- S*65535, H <- H
32-bit images:
H, S, V are left as is

If the original image is float, you should manually convert the pixel values in the original image to [0, 1].

The ICRA 2011 conference at Shanghai, China

Well, ICRA2011 was a very amazing conference, where I met a lot of famous experts in robotics and computer vision, such as Marc Pollefeys, Stan Birchfield, Shoudong Huang, Chieh-Chih Wang, Larry Matthies and Ryan Eustice, etc. Although I did not try to talk with them all because I am a little nervous and shy, I am very exciting to see them face to face.
About my talk, it was my first conference talk, so some mistakes happened, for instance, wrong pronunciation for some words. I forgive myself here. This experience will let me learn and make further progress on the next conferences.
Thanks my friends and prior college Kejun Ning, who made a photo when I gave the talk.

Thursday, May 26, 2011

opencv2.0: a bug in the function convertBGRImageToOpponentColorSpace

The O1 in the opponent color space should be red - green, but in the code, it shows:

int value = static_cast( static_cast(static_cast(*gIt)-static_cast(*rIt)) * factor );

which is wrong.