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

No comments: