Hello,
I am starting to use OpenV with Java. I have written an app to capture video from my usb cam and wanted to test it for a web camera using a rstp address. I can use the rstp with VLC player so I know it works but I don't know how to modify my OpenCV code. Please help.
The result I get is that the return mat2Img.getImage(mat2Img.mat) = null which results in Exception. I came across the solution that the cameras frame is accessible for a small period of time but I am not sure if this is the case here. Here is the code:
public class VideoGrabber {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
VideoCapture cap;
Mat2Image mat2Img = new Mat2Image();
public VideoGrabber(){
cap = new VideoCapture();
try {
System.out.println("Sleeping..");
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Camera on..");
cap.open("rtsp://admin:admin@192.168.1.14:554/cam/realmonitor?channel=1&subtype=0?tcp");
if(!cap.isOpened()){
System.out.println("Camera Error");
}
else{
System.out.println("Camera OK?");
}
}
BufferedImage getOneFrame() {
cap.read(mat2Img.mat);
return mat2Img.getImage(mat2Img.mat);
}
}
Please help.
↧