网络摄像头型号
海康威视DS-2CD3345-1 2.8mm
参数: 400万 红外30米 PoE供电 焦距2.8mm
协议及设置地址
协议: rtsp
设置地址: rtsp://admin:jdrx1234567@192.168.60.30:554/h264/ch1/sub/av_stream
代码版本
openCV : 3.4.10
依赖的javacv :
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.5.3</version>
</dependency>
测试代码
@Test
public void testRtsp() {
//必须要加入这两个东西
System.load("D:\\Programs\\opencv\\build\\x64\\vc15\\bin\\opencv_world3410.dll");
System.load("D:\\Programs\\opencv\\build\\bin\\opencv_ffmpeg3410_64.dll");
VideoCapture vc = new VideoCapture();
boolean isOpen = vc.open("rtsp://admin:jdrx1234567@192.168.60.30:554/h264/ch1/sub/av_stream");
System.out.println("isOpen="+isOpen);
Mat mat = new Mat();
String winName = "showFrame";
int height = 600,width = 800;
HighGui.namedWindow(winName);
HighGui.resizeWindow(winName, width, height);
while(vc.read(mat)){
System.out.println("read.......");
// 重置大小
Mat dst = new Mat();
Imgproc.resize(mat, dst, new Size(width,height));
// 显示
HighGui.imshow(winName, dst);
// waitkey 必须要,否则无法显示
int key = HighGui.waitKey(1);
System.out.println("key="+key);
//esc键退出
if(key == 27){
break;
}
//拿到了每帧之后要干嘛就是后面逻辑的事情了
}
HighGui.destroyAllWindows();
vc.release();
}
此代码摘抄自网络。
测试效果
录屏