- 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)
- 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.
- Extract opencv to C:
- 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\; ”.
- Download and extract javacv Link. This contains 8 jar files
- 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.
- Check the following code. This captures an image from the web cam.
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 - next...so on
final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
try {
grabber.start();
IplImage img = grabber.grab();
if (img != null) {
cvSaveImage("capture.jpg", img);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
captureFrame();
}
}
- 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