Image processing with LibJacket + OpenCV

Update: one year later: ArrayFire+OpenCV

The OpenCV library is the de-facto standard for doing computer vision and image processing research projects. OpenCV includes several hundreds of computer vision algorithms, aimed for use in real-time vision applications.

LibJacket is a matrix library built on CUDA. LibJacket offers hundreds of general matrix and image processing functions, all running on the GPU. The syntax is very high level and easy to use.

LibJacket with OpenCV

For anyone out there interested in using both libraries together (ie. wanting parts of their code to run faster on a GPU very easily), I have put together a simple example application that demonstrates using OpenCV’s for webcam access and LibJacket for some basic processing routines and displaying results.

[ Linux/Mac Only ]
To run this example, simply download the source code (webcam_demo.cpp) and Makefile HERE, and place them in your libjacket/examples/image/ directory, and type:
make && ./webcam_demo
You must have a copy of LibJacket and OpenCV installed first, of course!

Sample code

Excerpt code snippit from webcam_demo.cpp:

// extract cv image
Mat mgray (img.rows, img.cols, CV_8UC1);
cvtColor(img.t(), mgray, CV_BGR2GRAY);
mgray.convertTo(mgray, CV_32FC1);
float* fgray = (float*)mgray.data;


// copy to gpu
f32 I1 = f32(fgray, img.rows, img.cols);


// display window
figure(); colormap("gray");
subplot(3, 3, 1); imagesc(I1); title("source image");


// process
...
...

 

 

New Example!: TV-L1 optical flow using LibJacket!

Update: one year later: ArrayFire+OpenCV

11 thoughts on “Image processing with LibJacket + OpenCV”

  1. Very interesting. I’m assuming you need to recompile and re-build the OpenCV library. Otherwise, how can the OpenCV routines run on the device?

    Please clarify.

    Thanks,
    Prashanth Bhat

  2. Hi Prashanth,
    There is no recompiling needed here; simply install OpenCV and LibJacket, and your’re done.
    All OpenCV code runs on the CPU and all LibJacket code runs on the GPU, automatically.
    The example above simply shows how to share data between the two libraries.
    Thanks for your interest!
    ~Chris

  3. Thanks for the clarification. I had initially thought that the OpenCV code also runs on the GPU.

  4. Kirill:
    Thanks! Indeed, I meant to do a comparison of OpenCV’s GPU module against LibJacket’s, but got sidetracked by school.
    I’m putting this back on my TODO list now, and hope to have some results to show by the end of this week, so stay tuned!

  5. genideveloper:

    Please see the README included with ViewerCV, and the comments on the ViewerCV webpage [http://mcclanahoochie.com/blog/portfolio/computer-vision-on-android-opencv/]. I’m sure you can get it working with those resources. If not, then I will be glad to answer any specific questions you have.

    ~Chris

Leave a Comment