用于 Java 的 OpenCV 上的 IP 网络摄像头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24843181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IP Webcam on OpenCV for Java
提问by Vinicius Nogueira
I am using IP Webcam APP for android and it is streaming MJPEG video through the local url :
我正在使用适用于 android 的 IP 网络摄像头 APP,它正在通过本地 url 流式传输 MJPEG 视频:
http://192.168.0.2:8080/video
I was able to show the video using VLC player and this piece of code in C++. On the OpenCV 2.2 I opened the url using:
我能够使用 VLC 播放器和 C++ 中的这段代码来显示视频。在 OpenCV 2.2 上,我使用以下命令打开了 url:
VideoCapture cap;
cap.open("http://192.168.0.2:8080/video?dummy=param.mjpg");
It worked in C++, but I want it to work in Java. I was able to run OpenCV2.4.9 using Java when taking pictures from my built in webcam. This is my code for taking the images from a url in Java.
它适用于 C++,但我希望它适用于 Java。从内置网络摄像头拍摄照片时,我能够使用 Java 运行 OpenCV2.4.9。这是我从 Java 中的 url 获取图像的代码。
System.loadLibrary("opencv_java249");
VideoCapture capture = new VideoCapture();
capture.open("http://192.168.0.2:8080/video?dummy=param.mjpg");
But the capture.open does not open the streaming and I could not debug it properly. I know that it might be a issue with the ffmpeg, since it works on OpenCV2.2. I also know that my OpenCV2.2 is specific for MS 2010 and might be more complete.
但是 capture.open 没有打开流媒体,我无法正确调试它。我知道这可能是 ffmpeg 的问题,因为它适用于 OpenCV2.2。我也知道我的 OpenCV2.2 特定于 MS 2010,可能更完整。
Would it help if I compile the OpenCV2.4.9 from sources? Is there a file that I could add to solve that problem? Is there another way of receiving the video from the IP camera and using on OpenCV?
如果我从源代码编译 OpenCV2.4.9 会有帮助吗?有没有我可以添加的文件来解决这个问题?是否有另一种方式从 IP 摄像机接收视频并在 OpenCV 上使用?
回答by Vinicius Nogueira
I took a while to figure it out. I could not receive the stream directly from OpenCVJava.I downloaded
我花了一段时间才弄明白。我无法直接从 OpenCVJava 接收流。我下载了
http://www.mediafire.com/download/ayxwnwnqv3mpg39/javacv-0.7-bin.ziphttp://www.mediafire.com/download/2rkk0rjwxov7ale/javacv-0.7-cppjars.zip
http://www.mediafire.com/download/ayxwnwnqv3mpg39/javacv-0.7-bin.zip http://www.mediafire.com/download/2rkk0rjwxov7ale/javacv-0.7-cppjars.zip
Which I believe to be a java wrapper into OpenCV in C. I took this link from this video.
我相信它是 C 语言中 OpenCV 的 Java 包装器。我从这个视频中获取了这个链接。
htttp://www.youtube.com/watch?v=mIYaHCyZICI
http://www.youtube.com/watch?v=mIYaHCyZICI
After unziping the zip I added the jars into my project and Used this code:
解压缩 zip 后,我将 jars 添加到我的项目中并使用以下代码:
package javaapplication7;
import java.io.IOException;
import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
public class JavaApplication7 {
public static void main(String[] args) throws Exception {
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("http://192.168.0.2:8080/video?dummy=param.mjpg");
grabber.setFormat("mjpeg");
grabber.start();
for (int k=0; k<20000; k++){
System.out.print(k);
}
IplImage frame = grabber.grab();
CanvasFrame canvasFrame = new CanvasFrame("Camera");
canvasFrame.setCanvasSize(frame.width(), frame.height());
while (canvasFrame.isVisible() && (frame = grabber.grab()) != null) {
canvasFrame.showImage(frame);
}
grabber.stop();
canvasFrame.dispose();
System.exit(0);
}
}
Which I got from:
我从中得到的:
htttp://stackoverflow.com/questions/14251290/cvcreatefilecapture-error-could-not-create-camera-capture-with-javacv
http://stackoverflow.com/questions/14251290/cvcreatefilecapture-error-could-not-create-camera-capture-with-javacv
It takes 15-20 seconds to start catching the streaming. But I was impressed with the delay which is much smaller than VLC. It is 1-2 seconds comparing to 3-4 seconds on VLC. I would like to upvote the guy who I took the answer from but I dont have enough reputation/
开始捕捉流媒体需要 15-20 秒。但我对比 VLC 小得多的延迟印象深刻。与 VLC 上的 3-4 秒相比,它是 1-2 秒。我想投票给我回答的那个人,但我没有足够的声誉/