我正在尝试使用OpenCV在java中创建一个应用程序来从Web服务中获取视频流,这是一个带有几个摄像头和录制设备的摄像头系统 .
我找到了地址“rtsp:// login:pass @ IP address:port / cam / realmonitor?channel = 1&subtype = 0”来访问通道1上的摄像头 .
为了打开相机流我已经使用了这个代码(它可以捕获一个本地的usb相机):
VideoCapture上限; Mat2Image mat2Img = new Mat2Image();
public VideoGrabber(){
cap = new VideoCapture(0);
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("0");
if(!cap.isOpened()){
System.out.println("Camera Error");
}
else{
System.out.println("Camera OK?");
}
}
在抓取视频流后,我将其放入JFrame中 .
我想我应该将视频流服务地址放在cap.open(...)中,但是使用rtsp:// login:pass @ http://192.168.1.14:8006/cam/realmonitor?channel=1&subtype=0给了我"Exception in thread " AWT-EventQueue-0 " java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0" .
请帮忙,
编辑我发现rtsp:// login:pass @ http://192.168.1.14: 554 / cam / realmonitor?channel = 1&subtype = 0在vlc中工作但在opencv中仍然没有运气 .
编辑#2好的 . 在玩了vlcl,gstreamer和大多数流行的解决方案后,它才刚刚起步 . 毕竟我不知道rtsp地址是不是坏了 . 码:
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//load the library of opencv
}
VideoCapture cap;
Mat2Image mat2Img = new Mat2Image();
Mat matFilter = new Mat();
public VideoGrabber(){
cap = new VideoCapture();
try {
System.out.println("Sleeping..");
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Camera on..");
cap.open("rtsp://login:pass@192.168.1.14:554/cam/realmonitor?channel=1&subtype=0");
if(!cap.isOpened()){
System.out.println("Camera Error");
}
else{
System.out.println("Camera OK?");
}
}
1 回答
回答我的问题和Fouad我发布工作代码:我猜测答案是加载ffmpeg dll .