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");
System.loadLibrary("opencv_java244");
VideoCapture camera = new VideoCapture(0);
camera.open(0);
if(!camera.isOpened()){
System.out.println("Camera Error");
}
else{
System.out.println("Camera OK?");
}
Mat frame = new Mat();
camera.read(frame);
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " + frame.width());
Highgui.imwrite("camera.jpg", frame);
System.out.println("OK");
}
}
source
share