Saturday, January 19, 2013

Setting-up javaCV on NetBeans and Eclipse

JavaCV is a set of wrapper classes used for openCV. Using javaCV any C code used for Image Processing can be converted in to a java code. For a person who have an expertise knowledge on java and a little knowledge on C, javaCV will be very useful as he only have to worry about the logic of the code not the syntax. Following is a guide to install and configure javaCV in netbeans or eclipse environment.
  1. Install Microsoft Visual C++ Microsoft Visual C++ 2010 Redistributable Package (x86) or Microsoft Visual C++ 2010 Redistributable Package (x64) (If your system is 64 bit) 
  2. Download opencv 2.4.0 OpenCV windows SuperPack version 2.4.0 
      • Note- Opencv 2.4.1 does not work with this. It gives a linking error.
  3. Extract opencv to C: 
  4. Set up environment variables
    • 64-bit version of the JDK: C:\opencv\build\common\tbb\intel64\vc10\;C:\opencv\build\x64\vc10\bin\; 
    • 32-bit version of the JDK: C:\opencv\build\common\tbb\ia32\vc10\;C:\opencv\build\x86\vc10\bin\;                                       ”.
  5. Download and extract javacv Link. This contains 8 jar files
  6. When creating projects add those jar files to the libraries folder
    •  In netbeans right click Libraries and select ”add JAR/folder” and select above jar files.
    •  In eclipse right click the project folder and select properties. Select “java build path” and select the Libraries tab and add the required jar files.
  7. Check the following code. This captures an image from the web cam.
import com.googlecode.javacv.OpenCVFrameGrabber; 
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_highgui.*; 

public class CaptureImage {

private static void captureFrame() { 
  // 0-default camera, 1 - on 
  final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
  try { 
    IplImage img = grabber.grab();
    if (img != null) { 
      cvSaveImage("capture.jpg", img);
  } catch (Exception e) { 

public static void main(String[] args) { 

  • You can find the captured picture on the project folder. To change the camera change the number that is passed to the OpenCVFrameGrabber constructor.

Sutra Directory