Equations

Friday, June 7, 2013

Frame Capture Issue with OpenCV under Windows 7

A serious issue that arises when using OpenCV under windows 7 is the use of opencv_highgui or openCVFrameGrabber for capturing frames from WebCam or a video file. In this case, OpenCv uses video for windows codec which isn’t always working well under windows 7.


A solution to this problem is to use VideoInputFrameGrabber for WebCam which uses DirectShow and FFmpegFrameGrabber with a version of FFmpeg codec to read video files.

Javacv code sample:

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(new File(video_file_path));
try {
    grabber.start();
    for (int i = 0; i < 10; i++) {
        opencv_core.IplImage currentFrame = grabber.grab();
        ......
    }
} catch (Exception ex) {
    .....
}

Building a DLL With JNI support under Windows (32bit versus 64bit)

Java provides us with JNI to link java projects with C++ code. I’m using Netbeans IDE which has a good C++ support With Cygwin tools and I needed to use a C++ implementation for multilabel graphcut optimization in one of my java projects.
The problem I encountered is the different settings needed to build a DLL library under 32bit and 64bit environments. Here is the settings I used to build under the different environments,

JNI:
Include: $jdk_home$/include ; $jdk_home$/include/win32

Win32bit:
I used the g++ compiler with the following options
-mno-cygwin -Wl,—add-stdcall-alias -shared -m32

Win64bit:
I used the x86_64-w64-mingw32-g++ compiler with the following options
-w -mno-cygwin -static -shared