Month: February 2014

I use the motion template Processing program in the previous post to render a number of classic film sequences from IGN. Through the motion components returned from each frame, I draw a square by picking up the colour of the pixel at that location.

The following example ported the original OpenCV motion template sample code in C to Java/Processing. The original source is the motempl.c file in the OpenCV distribution.

The program started using the default video capture device and passed it to the class Motion. It employed the accumulated difference images to segment into different motion regions, delivered back with a list of rectangles, indicating where the motion components are. It then returned to the Processing main program with an ArrayList of the class Result.

This example illustrates the use of the Java version of OpenCV. I built the OpenCV 2.4.8 in Mac OSX 10.9. After building, I copied the following two files to the code folder of the Processing sketch:

opencv-248.jar

libopencv_java248.dylib

The program initialised the default video capture device. It converted the PImage first into an OpenCV matrix – Mat. The matrix is duplicated into another copy and then converted back to another PImage for display with the image command.

It can achieve around 60 frame per second in my old iMac. Here is the screenshot.

My former post described the steps to build OpenCV from source in OSX. With OSX 10.9 and the latest Xcode 5.0.2, there are changes before I can build the OpenCV again. I refer to this post for the building process.

In this configuration, I do not need to specify in the ccmake command line the C and CXX compiler. For machine with CUDA, I use /usr/bin/clang for the CUDA_HOST_COMPILER option. After the generation phase of the ccmake process, I manually edit the CMakeCache.txt file to alter some more options.

For CUDA_NVCC_FLAGS, the options are -Xcompiler -stdlib=libstdc++; -Xlinker -stdlib=libstdc++

For CMAKE_CXX_FLAGS and CMAKE_EXE_LINKER_FLAGS, the option is -stdlib=libstdc++

The second option will instruct the build process not to use the new C++11 library that may cause compilation errors in openFrameworks.