我有Tenvis IP摄像头,用户名和密码。我想在Eclipse IDE中使用 OpenCV 开发的简单Java应用程序中捕获实时照片或视频。
我正在使用以下代码来实现我的目的。
public class Hello {
public static void main( String[] args )
{
try
{
System.out.println("Welcome to OpenCV " + Core.VERSION);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
// VideoCapture cap= new VideoCapture("D:/css/pizzavideo.mp4");
VideoCapture cap = new VideoCapture("http://192.168.2.106:7777/video/livesp.asp?
user=admin&pwd=admin&resolution=32");
if(cap.isOpened())
{
System.out.println(" camera found----"+cap);
Mat frame = new Mat();
while(true){
if (cap.read(frame)){
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " + frame.width() + " Height " + frame.height());
Highgui.imwrite("img1.jpg", frame);
System.out.println("OK");
break;
}
}
}
else
{
System.out.println("Did not connect to camera");
}
cap.release();
}
catch(Exception e)
{
System.out.println("Exception---"+e.getMessage());
}
}
}
结果:
When using http://192.168.2.106:7777/video/livesp.asp? user=admin&pwd=admin&resolution=32
Welcome to OpenCV 2.4.8.0
m = [1, 0, 0;
0, 1, 0;
0, 0, 1]
Did not connect to camera
结果(我成功获取视频帧为img1.jpg):使用D时:/css/pizzavideo.mp4
Welcome to OpenCV 2.4.8.0
m = [1, 0, 0;
0, 1, 0;
0, 0, 1]
camera found----org.opencv.highgui.VideoCapture@87816d
Frame Obtained
Captured Frame Width 480 Height 262
OK
如果有人知道如何连接我的IP摄像机并在我的java应用程序中拍摄照片或视频,请回复吗?