OpenCV 2.4.4 Java - Webcam Image / Stream Capture (OSX)

I am new to the world of Stackoverflow and OpenCV programming. I did some projects with OpenCV Bindings for Java (officials of opencv.org, not JavaCV), like object recognition through ORB and SURF functions, working with images. Everything is fine. Now I turn to the recognition of objects in video streams. I want to capture a stream from a webcam and apply object recognition. I am not a Java guru, so I found the VideoCapture class in OpenCV, but I cannot get photos from the camera.

I run my project in Eclipse with OpenCV 2.4.4 bindings, in OSX Mountain Lion.

Result in the console:

Hello, OpenCV
Camera OK?
Frame Obtained
Captured Frame Width 0
Invalid memory access of location 0x7fae00000000 rip=0x7fff8b4c5263

The code:

import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;

public class Webcam {

    public static void main (String args[]){

    System.out.println("Hello, OpenCV");
    // Load the native library.
    System.loadLibrary("opencv_java244");

    VideoCapture camera = new VideoCapture(0);
    camera.open(0); //Useless
    if(!camera.isOpened()){
        System.out.println("Camera Error");
    }
    else{
        System.out.println("Camera OK?");
    }

    Mat frame = new Mat();

    //camera.grab();
    //System.out.println("Frame Grabbed");
    //camera.retrieve(frame);
    //System.out.println("Frame Decoded");

    camera.read(frame);
    System.out.println("Frame Obtained");

    /* No difference
    camera.release();
    */

    System.out.println("Captured Frame Width " + frame.width());

    Highgui.imwrite("camera.jpg", frame);
    System.out.println("OK");
    }
}
+5
source share
3 answers

, .

Thread.sleep(1000);

VideoCapture camera = new VideoCapture(0);
+7

MacOS .

System.loadLibrary("opencv_java244");

java.lang.UnsatisfiedLinkError: org.opencv.highgui.VideoCapture.VideoCapture_2(I)J

,

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

!

opencv 2.4.8, eclipse

+3

Replace
System.loadLibrary("opencv_java244");
with
 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

+3
source

All Articles