This tutorial is about how to use PointGrey's Camera (a CCD vendor from Cadana) by using their FlyCapture SDK(C/C++) as an interface connecting with Java in Ubuntu.
Prepare a PointGrey(PG) camera, Fly Capture SDK, and probably Netbeans IDE. Now here we go.
ps. This tutorial using the C libraries of the SDK, not yet C++, but I believe the setup procedure is similar. If you wanna more powerful features, try C++.
- CCD: Chameleon CMLN-13S2C (connect to PC via USB 2.0)
- Fly Capture SDK version: 188.8.131.52 (amd64)
- OS: Ubuntu 12.04 LTS (desktop manager is by default)
- Compiler: gcc 4.6.3
- IDE: Netbeans 7.3
- Java version: 1.6.0_27 OpenJDK Runtime Environment 64-Bit Server VM
Setting everything up
- Download the SDK and install it. It has dependencies, please checkout them in README before run install script.
After doing this, you will have C/C++ header files in
/usr/include/flycapture/ and dynamic libraries in
/usr/lib/, the library you need is
libflycapture-c.so. Besides, PointGrey also offer you the sample code to use the CCD. Open
/usr/src/flycapture you will see bin, lib, src directories.
Now you have some executable program in your computer, try to play with them to see if the connection to CCD via USB is built successfully.
OK, if you could run it without problems, you're on the half of the way. Personally I suggest copy the
/usr/src/flycapture folder into another place and play with it. For example:
And try to build the sample code:
Same as it for you to play with another C++ sample codes. Just remember to build FlyCapture2GUI first since all other C++ sample codes here require the GUI interface.
Now let's connect it to Java
The way for Java connect with C/C++ libraries is called Java Native Interface. You write Java codes and use java compiler auto-generated the C/C++ header interface by include preinstalled jni.h. And then include the auto-generated header interface in your C/C++ code and implement it!
It already generate the interface header file for you. Now Craate a Netbean C/C++ dynamic library project, add the FlyCapture2JNI_Interface.c and include PointGreyCameraInterface.h.
You also need to tell Netbeans to include the path of
FlyCapture2_C.h, if you're in Ubuntu, it's in
/usr/include/flycapture. And you need to add the path of
jni.h as well. If you don't know where it is:
Project Property -> C Compiler -> Include Directories -> add:
Now the compiler has everything to know: the
.c and included
.h files. You can compile now but will fail in runtime because you didn't tell where the needed libraries are.
Project Property -> Linker -> Additional Library Directories -> add: /usr/lib
Project Property -> Linker -> Libraries -> select: /usr/lib/flycapture-c.so and /usr/lib/flycapture.so
Project Property -> Linker -> Output -> specify where you want to place the dynamic link library file (.so), this dynamic link library (say, called libInterface.so) will need to be load into your Java project in the future. Remember to name this .so file with prefix "lib". Linux systme recognizes the library in this way. The library file libABC.so will then be include in Java by System.loadLibrary("ABC"), for example.
Now clean and build it, the libInterface.so should be generated, place it into somewhere.
OK, now you got all you need to let Java interact with C/C++ libraries by using libInterface.so. Coding in Java are comfortable but sometimes you need more efficiency, run faster. By this way, you could actually implement some criticle functions in C/C++ and use them in Java. Perfect!
Open a Java application project with Netbeans and add what you just forked, include them in a proper way. One thing to take care: In PointGreyCameraInterface.java, make sure the library you load is just the library you generated.
For this to work, you need to tell where this dynamic library is as usual:
Project Property -> Run -> VM Options -> add:
Done, enjoy =)