作者 钟来

模块整理

正在显示 29 个修改的文件 包含 680 行增加301 行删除
1 -package com.zhonglai.luhui.smart.feeder.config;  
2 -  
3 -  
4 -import com.google.gson.Gson;  
5 -import com.ruoyi.common.utils.GsonConstructor;  
6 -import org.springframework.beans.factory.annotation.Autowired;  
7 -import org.springframework.boot.autoconfigure.http.HttpMessageConverters;  
8 -import org.springframework.context.annotation.Configuration;  
9 -import org.springframework.http.converter.HttpMessageConverter;  
10 -import org.springframework.http.converter.json.GsonHttpMessageConverter;  
11 -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;  
12 -  
13 -import java.util.ArrayList;  
14 -import java.util.List;  
15 -  
16 -  
17 -//@Configuration  
18 -//public class HttpMessageConverterConfig {  
19 -// @Autowired  
20 -// public void configureHttpMessageConverters(HttpMessageConverters converters, Gson gson) {  
21 -// List<HttpMessageConverter<?>> converterList = new ArrayList<>(converters.getConverters());  
22 -// for (HttpMessageConverter<?> converter : converterList) {  
23 -// if (converter instanceof MappingJackson2HttpMessageConverter) {  
24 -// converterList.remove(converter);  
25 -// break;  
26 -// }  
27 -// }  
28 -//  
29 -// converterList.add(new GsonHttpMessageConverter(gson));  
30 -// }  
31 -//  
32 -//}  
  1 +package com.zhonglai.luhui.smart.feeder.config;
  2 +
  3 +import com.zhonglai.luhui.smart.feeder.dto.*;
  4 +
  5 +/**
  6 + * 运行数据
  7 + */
  8 +public class OperatingData {
  9 + public static SysConfig sysConfig = new SysConfig(); //系统配置
  10 + public static CameraData cameraData = new CameraData(); //摄像头数据
  11 + public static CameraConfig cameraConfig = new CameraConfig() ; //摄像头配置
  12 + public static FeederData feederData = new FeederData() ; //投料机数据
  13 + public static FeederConfig feederConfig = new FeederConfig() ; //投料机配置
  14 +}
@@ -2,7 +2,7 @@ package com.zhonglai.luhui.smart.feeder.config.manager; @@ -2,7 +2,7 @@ package com.zhonglai.luhui.smart.feeder.config.manager;
2 2
3 import com.zhonglai.luhui.smart.feeder.service.SrsService; 3 import com.zhonglai.luhui.smart.feeder.service.SrsService;
4 import com.zhonglai.luhui.smart.feeder.service.EhCacheService; 4 import com.zhonglai.luhui.smart.feeder.service.EhCacheService;
5 -import com.zhonglai.luhui.smart.feeder.service.SerialPortService; 5 +import com.zhonglai.luhui.smart.feeder.service.device.SerialPortService;
6 import com.zhonglai.luhui.smart.feeder.service.TerminalService; 6 import com.zhonglai.luhui.smart.feeder.service.TerminalService;
7 import org.slf4j.Logger; 7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
1 package com.zhonglai.luhui.smart.feeder.controller; 1 package com.zhonglai.luhui.smart.feeder.controller;
2 2
3 -import com.fazecast.jSerialComm.SerialPort;  
4 import com.ruoyi.common.core.domain.AjaxResult; 3 import com.ruoyi.common.core.domain.AjaxResult;
5 -import com.zhonglai.luhui.smart.feeder.dto.ConfigDto;  
6 import com.zhonglai.luhui.smart.feeder.dto.commd.*; 4 import com.zhonglai.luhui.smart.feeder.dto.commd.*;
7 -import com.zhonglai.luhui.smart.feeder.service.DeviceService;  
8 -import com.zhonglai.luhui.smart.feeder.service.SerialPortService; 5 +import com.zhonglai.luhui.smart.feeder.service.device.SerialPortService;
9 import io.swagger.annotations.Api; 6 import io.swagger.annotations.Api;
10 import io.swagger.annotations.ApiOperation; 7 import io.swagger.annotations.ApiOperation;
11 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
  1 +package com.zhonglai.luhui.smart.feeder.dto;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +import java.util.ArrayList;
  7 +
  8 +@Data
  9 +@Accessors(chain = true) //链式写法
  10 +public class CameraConfig {
  11 + /**
  12 + * 摄像头编号
  13 + */
  14 + private Integer captureNumber;
  15 +
  16 + /**
  17 + * 摄像头接口类型
  18 + * USB(通过控制盒子上的usb接口连接)
  19 + * RTSP(通过局域网ip为192.168.0.198并且支持rtsp直播协议的摄像头连接)
  20 + */
  21 + private String cameraInterfaceType;
  22 +
  23 + /**
  24 + * 反光阈值
  25 + */
  26 + private Integer reflectionThreshold;
  27 + /**
  28 + * 去噪调整内核大小,用来消除小的物体或噪声
  29 + */
  30 + private Integer kernelSize;
  31 + /**
  32 + * 最大反光阈值
  33 + */
  34 + private Integer maxValue;
  35 + /**
  36 + * 斜率范围对应的档位
  37 + */
  38 + private ArrayList<FishCurveControlCondition> absValue_command;
  39 + /**
  40 + * 是否显示原图
  41 + */
  42 + private Boolean veiwDto_isFrame;
  43 + /**
  44 + * 是否显示临时图
  45 + */
  46 + private Boolean veiwDto_isBinaryImage;
  47 + /**
  48 + * 是否显示面积
  49 + */
  50 + private Boolean veiwDto_isSize;
  51 + /**
  52 + * 是否显示斜率
  53 + */
  54 + private Boolean veiwDto_isAbsValue;
  55 +
  56 + /**
  57 + * 鱼群图像识别的频率
  58 + */
  59 + private Long identificationFrequency;
  60 +
  61 + /**
  62 + * 鱼群图像识别是否开启
  63 + */
  64 + private Boolean fishGroupImageRecognition;
  65 +
  66 + /**
  67 + * 鱼群图像识别投料控制是否开启
  68 + */
  69 + private Boolean feedingControl;
  70 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class CameraData {
  9 + /**
  10 + * 斜率
  11 + */
  12 + private Double absValue;
  13 +
  14 + /**
  15 + * 面积大小
  16 + */
  17 + private Integer size;
  18 +
  19 + /**
  20 + * 视频是否打开
  21 + */
  22 + private boolean videoIsOpen;
  23 +
  24 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class FeederConfig {
  9 + private SerialPortConfig serialPortConfig;
  10 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class FeederData {
  9 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class SysConfig {
  9 + /**
  10 + * 是否上报数据
  11 + */
  12 + private Boolean ifUpLoadData;
  13 +
  14 + /**
  15 + * 是否显示
  16 + */
  17 + private Boolean ifVeiw;
  18 +
  19 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto.mqtt;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +import java.util.List;
  7 +
  8 +@Data
  9 +@Accessors(chain = true) //链式写法
  10 +public class CfgdataRequest {
  11 + private String cmd; //操作指令 devicedata
  12 + private String type; //设备网络型号 字符串("4G.hs")
  13 + private Condata condata;
  14 + private Info info;
  15 + private List<Integer[]> timer; //开启、关闭、使能 8:00开启-9:00关闭,状态:启用
  16 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto.mqtt;
  2 +
  3 +import io.swagger.models.auth.In;
  4 +import lombok.Data;
  5 +import lombok.experimental.Accessors;
  6 +
  7 +@Data
  8 +@Accessors(chain = true) //链式写法
  9 +public class CfgdataResponse {
  10 + private String cmd; //操作指令 devicedata
  11 + private String type; //设备网络型号 字符串("4G.hs")
  12 + private Integer backstate; //返回状态
  13 + private Integer errorcode; //错误代码
  14 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto.mqtt;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class Condata
  9 +{
  10 + private Integer runmode; //运行模式 0手动、1自动
  11 + private Integer runspeed; //运行速度(档位) 0-99档
  12 + private Integer worktime; //工作时间 1-18秒
  13 + private Integer interval; //时间间隔 1-18秒
  14 + private Integer runstate; //运行状态 1运行、3停止(平台可以设置0启动中,2关闭中,4异常)
  15 + private Integer stopfeedcnt; //手动投料倒计时时间 单位分
  16 + private Integer onoff; //运行状态 1运行、3停止(平台可以设置0启动中,2关闭中,4异常)
  17 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto.mqtt;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +import java.util.List;
  7 +
  8 +@Data
  9 +@Accessors(chain = true) //链式写法
  10 +public class DevicedatRequest {
  11 + private String cmd; //操作指令 devicedata
  12 + private String type; //设备网络型号 字符串("4G.hs")
  13 + private String signal; //信号量
  14 + private String machstate; //机器状态
  15 + private String battlevel; //电池电量
  16 + private Condata condata;
  17 + private Info info;
  18 + private List<Integer[]> timer; //开启、关闭、使能 8:00开启-9:00关闭,状态:启用
  19 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto.mqtt;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class DevicedatResponse {
  9 + private String cmd; //操作指令 devicedata
  10 + private String type; //设备网络型号 字符串("4G.hs")
  11 + private Integer backstate; //返回状态
  12 + private Integer errorcode; //错误代码
  13 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto.mqtt;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class Info
  9 +{
  10 + private String mfrs; //厂家名称 字符串("中渔科技")
  11 + private Integer equitype; //设备网络型号 0:投料机,1:增氧机,2:网络摄像头云台控制器
  12 + private Integer equimode; //设备子类型 0:振动式,1:螺旋式A,2:螺旋式B
  13 + private Integer faultcode; //故障代码 0正常,1-99故障
  14 + private Integer fodderstate; //饲料状态 0无料,1有料
  15 + private Float fodderweight; //饲料重量 0-9999(0-999)公斤
  16 + private Integer feednum; //投料次数 1-N
  17 + private Integer feedweight; //本次投料量 0-9999公斤
  18 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto.mqtt;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class ManualcontrolRequest {
  9 + private String cmd; //操作指令 devicedata
  10 + private String type; //设备网络型号 字符串("4G.hs")
  11 + private Condata condata;
  12 +}
  1 +package com.zhonglai.luhui.smart.feeder.dto.mqtt;
  2 +
  3 +import lombok.Data;
  4 +import lombok.experimental.Accessors;
  5 +
  6 +@Data
  7 +@Accessors(chain = true) //链式写法
  8 +public class ManualcontrolResponse {
  9 + private String cmd; //操作指令 devicedata
  10 + private String type; //设备网络型号 字符串("4G.hs")
  11 + private Integer backstate; //返回状态
  12 + private Integer errorcode; //错误代码
  13 +}
@@ -24,87 +24,7 @@ public class OpenCVUtil { @@ -24,87 +24,7 @@ public class OpenCVUtil {
24 24
25 } 25 }
26 26
27 - public static VideoCapture readVideoCaptureForRtsp()  
28 - {  
29 -// FFmCameraService fFmCameraService = new FFmCameraService();  
30 -// String ip = fFmCameraService.findCameraIp();  
31 - String ip = "192.168.0.198";  
32 - if(StringUtils.isEmpty(ip))  
33 - {  
34 - logger.info("未检测到摄像头{},尝试打开本地视频",MP4_FILE_PATH);  
35 - //如果找不到摄像头就找本地视频文件  
36 - File file = new File(MP4_FILE_PATH);  
37 - if(file.exists() && file.isFile())  
38 - {  
39 - VideoCapture videoCapture = OpenCVUtil.readVideoCaptureForVideo(MP4_FILE_PATH);  
40 - return videoCapture;  
41 - }  
42 - logger.info("未检测到摄像头!!!");  
43 - }  
44 - String rtspUrl = "rtsp://admin:Luhui586@"+ip+":554/h264/ch1/main/av_stream";  
45 - VideoCapture videoCapture = new VideoCapture(rtspUrl);  
46 - while (!videoCapture.isOpened())  
47 - {  
48 - try {  
49 - Thread.sleep(1000);  
50 - } catch (InterruptedException e) {  
51 - throw new RuntimeException(e);  
52 - }  
53 - }  
54 - return videoCapture;  
55 - }  
56 27
57 - public static VideoCapture readVideoCaptureForVideo(int i)  
58 - {  
59 - logger.info("初始化摄像头");  
60 - try {  
61 - Thread.sleep(3000);  
62 - } catch (InterruptedException e) {  
63 - throw new RuntimeException(e);  
64 - }  
65 - VideoCapture videoCapture = new VideoCapture();  
66 - boolean isopen = videoCapture.open(i);  
67 - if(isopen)  
68 - {  
69 - logger.info("打开化摄像头"+i+"成功");  
70 - return videoCapture;  
71 - }else {  
72 - logger.info("打开化摄像头"+i+"失败");  
73 - }  
74 - return null;  
75 - }  
76 - private static final String MP4_FILE_PATH = "D:/lh-smart-feeder/mp4/2.mp4";  
77 - public static VideoCapture openCapture()  
78 - {  
79 - for(int i=0;i<10;i++)  
80 - {  
81 - VideoCapture videoCapture = readVideoCaptureForVideo(i);  
82 - if(null != videoCapture)  
83 - {  
84 - return videoCapture; //拿到的第一个摄像头返回  
85 - }  
86 - }  
87 - logger.info("未检测到摄像头{},尝试打开本地视频",MP4_FILE_PATH);  
88 - //如果找不到摄像头就找本地视频文件  
89 - File file = new File(MP4_FILE_PATH);  
90 - if(file.exists() && file.isFile())  
91 - {  
92 - VideoCapture videoCapture = OpenCVUtil.readVideoCaptureForVideo(MP4_FILE_PATH);  
93 - return videoCapture;  
94 - }  
95 -  
96 - logger.info("未检测到摄像头!!!");  
97 - return null;  
98 - }  
99 -  
100 - public static VideoCapture readVideoCaptureForVideo(String videoPath )  
101 - {  
102 - // 创建VideoCapture对象  
103 - VideoCapture videoCapture = new VideoCapture();  
104 - boolean isopen = videoCapture.open(videoPath);  
105 - System.out.println(isopen);  
106 - return videoCapture;  
107 - }  
108 28
109 /** 29 /**
110 * 抠图 30 * 抠图
@@ -2,15 +2,11 @@ package com.zhonglai.luhui.smart.feeder.service; @@ -2,15 +2,11 @@ package com.zhonglai.luhui.smart.feeder.service;
2 2
3 import cn.hutool.core.bean.BeanUtil; 3 import cn.hutool.core.bean.BeanUtil;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 -import com.google.gson.JsonObject;  
6 -import com.ruoyi.common.utils.GsonConstructor;  
7 -import com.zhonglai.luhui.smart.feeder.Main;  
8 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter; 5 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter;
9 import com.zhonglai.luhui.smart.feeder.dto.ModbusDto; 6 import com.zhonglai.luhui.smart.feeder.dto.ModbusDto;
10 import com.zhonglai.luhui.smart.feeder.dto.StateData; 7 import com.zhonglai.luhui.smart.feeder.dto.StateData;
11 import com.zhonglai.luhui.smart.feeder.dto.VeiwDto; 8 import com.zhonglai.luhui.smart.feeder.dto.VeiwDto;
12 -import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommd03Response;  
13 -import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto; 9 +import com.zhonglai.luhui.smart.feeder.service.device.SerialPortService;
14 import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; 10 import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil;
15 import org.eclipse.paho.client.mqttv3.MqttException; 11 import org.eclipse.paho.client.mqttv3.MqttException;
16 import org.slf4j.Logger; 12 import org.slf4j.Logger;
@@ -18,8 +14,6 @@ import org.slf4j.LoggerFactory; @@ -18,8 +14,6 @@ import org.slf4j.LoggerFactory;
18 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Service; 15 import org.springframework.stereotype.Service;
20 16
21 -import javax.annotation.PostConstruct;  
22 -import java.io.IOException;  
23 import java.util.Map; 17 import java.util.Map;
24 import java.util.concurrent.ScheduledExecutorService; 18 import java.util.concurrent.ScheduledExecutorService;
25 import java.util.concurrent.TimeUnit; 19 import java.util.concurrent.TimeUnit;
@@ -2,6 +2,7 @@ package com.zhonglai.luhui.smart.feeder.service; @@ -2,6 +2,7 @@ package com.zhonglai.luhui.smart.feeder.service;
2 2
3 import com.ruoyi.common.utils.GsonConstructor; 3 import com.ruoyi.common.utils.GsonConstructor;
4 import com.zhonglai.luhui.smart.feeder.dto.*; 4 import com.zhonglai.luhui.smart.feeder.dto.*;
  5 +import com.zhonglai.luhui.smart.feeder.service.device.SerialPortService;
5 import com.zhonglai.luhui.smart.feeder.util.FeederCommd06ResponseType; 6 import com.zhonglai.luhui.smart.feeder.util.FeederCommd06ResponseType;
6 import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; 7 import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil;
7 import org.slf4j.Logger; 8 import org.slf4j.Logger;
@@ -2,11 +2,13 @@ package com.zhonglai.luhui.smart.feeder.service; @@ -2,11 +2,13 @@ package com.zhonglai.luhui.smart.feeder.service;
2 2
3 import cn.hutool.core.util.ArrayUtil; 3 import cn.hutool.core.util.ArrayUtil;
4 import com.ruoyi.common.utils.StringUtils; 4 import com.ruoyi.common.utils.StringUtils;
  5 +import org.bytedeco.ffmpeg.global.avcodec;
5 import org.bytedeco.ffmpeg.global.avutil; 6 import org.bytedeco.ffmpeg.global.avutil;
6 import org.bytedeco.javacv.*; 7 import org.bytedeco.javacv.*;
7 import org.bytedeco.javacv.Frame; 8 import org.bytedeco.javacv.Frame;
8 import org.slf4j.Logger; 9 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service; 12 import org.springframework.stereotype.Service;
11 13
12 import java.awt.*; 14 import java.awt.*;
@@ -14,6 +16,8 @@ import java.awt.image.BufferedImage; @@ -14,6 +16,8 @@ import java.awt.image.BufferedImage;
14 import java.time.LocalDateTime; 16 import java.time.LocalDateTime;
15 import java.time.format.DateTimeFormatter; 17 import java.time.format.DateTimeFormatter;
16 import java.util.ArrayList; 18 import java.util.ArrayList;
  19 +import java.util.concurrent.ScheduledExecutorService;
  20 +import java.util.concurrent.TimeUnit;
17 21
18 @Service 22 @Service
19 public class FFmCameraService { 23 public class FFmCameraService {
@@ -23,6 +27,11 @@ public class FFmCameraService { @@ -23,6 +27,11 @@ public class FFmCameraService {
23 27
24 private OpenCVFrameConverter.ToOrgOpenCvCoreMat converter2 = new OpenCVFrameConverter.ToOrgOpenCvCoreMat(); 28 private OpenCVFrameConverter.ToOrgOpenCvCoreMat converter2 = new OpenCVFrameConverter.ToOrgOpenCvCoreMat();
25 29
  30 + @Autowired
  31 + private ScheduledExecutorService scheduledExecutorService;
  32 +
  33 + @Autowired
  34 + private SrsService srsService;
26 35
27 private static String MAC = "78-a6-a0-d2-bd-e1"; 36 private static String MAC = "78-a6-a0-d2-bd-e1";
28 37
@@ -37,6 +46,58 @@ public class FFmCameraService { @@ -37,6 +46,58 @@ public class FFmCameraService {
37 loadCamera(); 46 loadCamera();
38 } 47 }
39 48
  49 + public static void main(String[] args) {
  50 + pushCamera();
  51 + }
  52 +
  53 + public static void pushCamera()
  54 + {
  55 + String ip = "192.168.0.198";
  56 + String inputUrl = "rtsp://admin:Luhui586@" + ip + ":554/h264/ch1/main/av_stream";
  57 + String outputUrl = "rtmp://119.23.218.181:21935/live/70094a59d1d991d";
  58 +
  59 + try {
  60 + FFmpegFrameGrabber.tryLoad();
  61 + } catch (Exception e) {
  62 + throw new RuntimeException("Failed to load FFmpeg", e);
  63 + }
  64 +
  65 + FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputUrl);
  66 + grabber.setVideoOption("fflags", "nobuffer");
  67 + grabber.setVideoOption("rtsp_transport", "tcp");
  68 + grabber.setOption("stimeout", "2000000");
  69 + avutil.av_log_set_level(avutil.AV_LOG_ERROR);
  70 +
  71 + try {
  72 + grabber.start();
  73 + Frame frame = grabber.grabImage();
  74 + while (0 == frame.imageWidth)
  75 + {
  76 + Thread.sleep(1000);
  77 + }
  78 + FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputUrl, frame.imageWidth, frame.imageHeight);
  79 + recorder.setFormat("flv");
  80 + recorder.setFrameRate(30);
  81 + recorder.setVideoBitrate(2000000);
  82 + recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
  83 + recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
  84 +
  85 + recorder.start();
  86 +
  87 + Frame capturedFrame;
  88 + while ((capturedFrame = grabber.grabImage()) != null) {
  89 + recorder.record(capturedFrame);
  90 + }
  91 +
  92 + grabber.stop();
  93 + recorder.stop();
  94 +
  95 + System.out.println("摄像头流推送完成");
  96 + } catch (Exception e) {
  97 + e.printStackTrace();
  98 + }
  99 + }
  100 +
40 /** 101 /**
41 * 加载摄像头 102 * 加载摄像头
42 */ 103 */
@@ -59,6 +120,7 @@ public class FFmCameraService { @@ -59,6 +120,7 @@ public class FFmCameraService {
59 grabber = new FFmpegFrameGrabber(rtspUrl); 120 grabber = new FFmpegFrameGrabber(rtspUrl);
60 grabber.setVideoOption("fflags", "nobuffer"); // 禁用缓冲 121 grabber.setVideoOption("fflags", "nobuffer"); // 禁用缓冲
61 grabber.setVideoOption("rtsp_transport", "tcp"); // 使用TCP传输 122 grabber.setVideoOption("rtsp_transport", "tcp"); // 使用TCP传输
  123 + grabber.setOption("stimeout", "2000000");
62 avutil.av_log_set_level(avutil.AV_LOG_ERROR); // 设置日志级别 124 avutil.av_log_set_level(avutil.AV_LOG_ERROR); // 设置日志级别
63 125
64 try { 126 try {
@@ -67,6 +129,18 @@ public class FFmCameraService { @@ -67,6 +129,18 @@ public class FFmCameraService {
67 close(); 129 close();
68 e.printStackTrace(); 130 e.printStackTrace();
69 } 131 }
  132 +// scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
  133 +// @Override
  134 +// public void run() {
  135 +// if()
  136 +// {
  137 +// srsService.push(getFrame());
  138 +// }
  139 +//
  140 +// }
  141 +// },0,0, TimeUnit.MILLISECONDS);
  142 +
  143 +
70 } 144 }
71 145
72 public Boolean isOk() 146 public Boolean isOk()
@@ -119,9 +193,9 @@ public class FFmCameraService { @@ -119,9 +193,9 @@ public class FFmCameraService {
119 Frame frame = null; 193 Frame frame = null;
120 try { 194 try {
121 frame = grabber.grabImage(); 195 frame = grabber.grabImage();
122 - if (frame == null) { 196 + if (frame == null || frame.imageHeight==0) {
123 //TODO:连续n次为null,进行重连 197 //TODO:连续n次为null,进行重连
124 - System.out.println("frame is null"); 198 + logger.info("读取不到画面,当前grabber状态:hasAudio {},hasVideo {},isCloseInputStream {},isDeinterlace {},isTriggerMode {}",grabber.hasAudio(),grabber.hasVideo(),grabber.isCloseInputStream(),grabber.isDeinterlace(),grabber.isTriggerMode());
125 return null; 199 return null;
126 } 200 }
127 else{ 201 else{
@@ -40,8 +40,6 @@ public class FishGroupImageRecognitionService { @@ -40,8 +40,6 @@ public class FishGroupImageRecognitionService {
40 @Autowired 40 @Autowired
41 private DeviceService deviceService; 41 private DeviceService deviceService;
42 42
43 - @Autowired  
44 - private SrsService srsService;  
45 43
46 private static Boolean isRun = false; 44 private static Boolean isRun = false;
47 45
@@ -216,8 +214,6 @@ public class FishGroupImageRecognitionService { @@ -216,8 +214,6 @@ public class FishGroupImageRecognitionService {
216 214
217 veiwDto = new VeiwDto(new Double(area).intValue(),absValue); 215 veiwDto = new VeiwDto(new Double(area).intValue(),absValue);
218 216
219 - srsService.timepush(frame,absValue);  
220 -  
221 // 显示图像 217 // 显示图像
222 logger.info("是否显示{},客户端数量{}",configurationParameterService.getConfig(ConfigurationParameter.ifVeiw),WebSocketClien.webSocketSet.size()); 218 logger.info("是否显示{},客户端数量{}",configurationParameterService.getConfig(ConfigurationParameter.ifVeiw),WebSocketClien.webSocketSet.size());
223 // 在图像上显示结果 219 // 在图像上显示结果
@@ -8,8 +8,8 @@ import com.zhonglai.luhui.smart.feeder.dto.VeiwDto; @@ -8,8 +8,8 @@ import com.zhonglai.luhui.smart.feeder.dto.VeiwDto;
8 import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommd06Response; 8 import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommd06Response;
9 import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto; 9 import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto;
10 import com.zhonglai.luhui.smart.feeder.dto.commd.FeederTimer; 10 import com.zhonglai.luhui.smart.feeder.dto.commd.FeederTimer;
  11 +import com.zhonglai.luhui.smart.feeder.service.device.SerialPortService;
11 import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; 12 import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil;
12 -import com.zhonglai.luhui.smart.feeder.util.PenetrateUtil;  
13 import org.eclipse.paho.client.mqttv3.*; 13 import org.eclipse.paho.client.mqttv3.*;
14 import org.slf4j.Logger; 14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory; 15 import org.slf4j.LoggerFactory;
@@ -20,7 +20,6 @@ import org.springframework.stereotype.Component; @@ -20,7 +20,6 @@ import org.springframework.stereotype.Component;
20 import java.util.HashMap; 20 import java.util.HashMap;
21 import java.util.List; 21 import java.util.List;
22 import java.util.Map; 22 import java.util.Map;
23 -import java.util.concurrent.ScheduledExecutorService;  
24 23
25 @Component 24 @Component
26 public class MqttCallback implements MqttCallbackExtended { 25 public class MqttCallback implements MqttCallbackExtended {
@@ -314,41 +314,41 @@ public class SrsService { @@ -314,41 +314,41 @@ public class SrsService {
314 314
315 315
316 public static void main(String[] args) { 316 public static void main(String[] args) {
317 - OpenCVConfig.loadOpenCv(args);  
318 - SrsService srsService = new SrsService();  
319 - FishRegionPanel fishRegionPanel = new FishRegionPanel();  
320 - int i=0;  
321 - while (i++<10)  
322 - {  
323 - VideoCapture videoCapture = OpenCVUtil.readVideoCaptureForVideo("");  
324 - Mat previousFrame = new Mat();  
325 - if (!videoCapture.read(previousFrame)) {  
326 - System.out.println("无法读取视频帧");  
327 - return;  
328 - }  
329 -  
330 - try {  
331 - if(null == srsService.recorder || !srsService.recorder.isInterleaved())  
332 - {  
333 - srsService.init(previousFrame.width(),previousFrame.height());  
334 - }  
335 - } catch (Exception e) {  
336 - throw new RuntimeException(e);  
337 - }  
338 -  
339 - Mat src = new Mat();  
340 - while (videoCapture.read(src))  
341 - {  
342 - Mat mat = srsService.fish(src);  
343 - fishRegionPanel.getLblImage().setIcon(new ImageIcon(convertMatToImage(mat)));  
344 - fishRegionPanel.getFrame().repaint();  
345 - OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();  
346 - Frame frame = converter.convert(mat);  
347 - srsService.push(frame);  
348 - }  
349 -  
350 - }  
351 - srsService.close(); 317 +// OpenCVConfig.loadOpenCv(args);
  318 +// SrsService srsService = new SrsService();
  319 +// FishRegionPanel fishRegionPanel = new FishRegionPanel();
  320 +// int i=0;
  321 +// while (i++<10)
  322 +// {
  323 +// VideoCapture videoCapture = OpenCVUtil.readVideoCaptureForVideo("");
  324 +// Mat previousFrame = new Mat();
  325 +// if (!videoCapture.read(previousFrame)) {
  326 +// System.out.println("无法读取视频帧");
  327 +// return;
  328 +// }
  329 +//
  330 +// try {
  331 +// if(null == srsService.recorder || !srsService.recorder.isInterleaved())
  332 +// {
  333 +// srsService.init(previousFrame.width(),previousFrame.height());
  334 +// }
  335 +// } catch (Exception e) {
  336 +// throw new RuntimeException(e);
  337 +// }
  338 +//
  339 +// Mat src = new Mat();
  340 +// while (videoCapture.read(src))
  341 +// {
  342 +// Mat mat = srsService.fish(src);
  343 +// fishRegionPanel.getLblImage().setIcon(new ImageIcon(convertMatToImage(mat)));
  344 +// fishRegionPanel.getFrame().repaint();
  345 +// OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
  346 +// Frame frame = converter.convert(mat);
  347 +// srsService.push(frame);
  348 +// }
  349 +//
  350 +// }
  351 +// srsService.close();
352 352
353 } 353 }
354 } 354 }
  1 +package com.zhonglai.luhui.smart.feeder.service.device;
  2 +
  3 +import org.bytedeco.javacv.Frame;
  4 +
  5 +public interface CameraHandle {
  6 + public void init();
  7 + public org.opencv.core.Mat getMat();
  8 +
  9 +}
1 -package com.zhonglai.luhui.smart.feeder.service; 1 +package com.zhonglai.luhui.smart.feeder.service.device;
2 2
  3 +import com.ruoyi.common.utils.StringUtils;
  4 +import com.zhonglai.luhui.smart.feeder.config.OperatingData;
3 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter; 5 import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter;
4 -import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil;  
5 -import org.bytedeco.javacv.FrameGrabber;  
6 import org.opencv.videoio.VideoCapture; 6 import org.opencv.videoio.VideoCapture;
7 import org.slf4j.Logger; 7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.beans.factory.annotation.Value;
10 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
11 12
12 -import java.net.DatagramSocket; 13 +import java.io.File;
13 import java.util.concurrent.ScheduledExecutorService; 14 import java.util.concurrent.ScheduledExecutorService;
14 import java.util.concurrent.ScheduledFuture; 15 import java.util.concurrent.ScheduledFuture;
15 import java.util.concurrent.TimeUnit; 16 import java.util.concurrent.TimeUnit;
16 -import java.net.DatagramPacket;  
17 -import java.net.InetAddress;  
18 -import java.net.MulticastSocket;  
19 -import java.io.IOException;  
20 /** 17 /**
21 * 摄像头 18 * 摄像头
22 */ 19 */
@@ -24,23 +21,35 @@ import java.io.IOException; @@ -24,23 +21,35 @@ import java.io.IOException;
24 public class CameraService { 21 public class CameraService {
25 private static final Logger logger = LoggerFactory.getLogger(CameraService.class); 22 private static final Logger logger = LoggerFactory.getLogger(CameraService.class);
26 23
  24 + @Value("${sys.network_camera_ip}")
  25 + private String ip;
  26 + @Value("${sys.mp4_file_path}")
  27 + private String MP4_FILE_PATH;
  28 +
27 private VideoCapture videoCapture; 29 private VideoCapture videoCapture;
28 - private boolean videoIsOpen;  
29 30
30 private ScheduledFuture scheduledFuture; 31 private ScheduledFuture scheduledFuture;
31 32
32 @Autowired 33 @Autowired
33 private ScheduledExecutorService scheduledExecutorService; 34 private ScheduledExecutorService scheduledExecutorService;
34 35
35 - @Autowired  
36 - private ConfigurationParameterService configurationParameterService;  
37 -  
38 /** 36 /**
39 * 初始化摄像头 37 * 初始化摄像头
40 */ 38 */
41 private void openCapture() 39 private void openCapture()
42 { 40 {
43 - videoCapture = OpenCVUtil.readVideoCaptureForRtsp(); 41 + switch (OperatingData.cameraConfig.getCameraInterfaceType().toUpperCase())
  42 + {
  43 + case "USB":
  44 + videoCapture = readVideoCaptureForUSB();
  45 + break;
  46 + case "RTSP":
  47 + videoCapture = readVideoCaptureForRtsp();
  48 + break;
  49 + default:
  50 + videoCapture = readVideoCaptureForFile();
  51 + }
  52 +
44 if(null == videoCapture) 53 if(null == videoCapture)
45 { 54 {
46 return; 55 return;
@@ -56,11 +65,10 @@ public class CameraService { @@ -56,11 +65,10 @@ public class CameraService {
56 { 65 {
57 // 检查视频是否成功打开 66 // 检查视频是否成功打开
58 if (null !=videoCapture && videoCapture.isOpened()) { 67 if (null !=videoCapture && videoCapture.isOpened()) {
59 - videoIsOpen = true; 68 + OperatingData.cameraData.setVideoIsOpen(true);
60 return; 69 return;
61 } 70 }
62 - System.out.println("无法打开视频文件"+ configurationParameterService.getConfig(ConfigurationParameter.captureNumber));  
63 - videoIsOpen = false; 71 + OperatingData.cameraData.setVideoIsOpen(false);
64 } 72 }
65 73
66 /** 74 /**
@@ -71,8 +79,8 @@ public class CameraService { @@ -71,8 +79,8 @@ public class CameraService {
71 if(null == scheduledFuture || scheduledFuture.isDone()) 79 if(null == scheduledFuture || scheduledFuture.isDone())
72 { 80 {
73 scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> { 81 scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> {
74 - logger.info("摄像头状态{}",videoIsOpen);  
75 - if(!videoIsOpen) 82 + logger.info("摄像头状态{}",OperatingData.cameraData.isVideoIsOpen());
  83 + if(!OperatingData.cameraData.isVideoIsOpen())
76 { 84 {
77 openCapture(); 85 openCapture();
78 } 86 }
@@ -91,9 +99,9 @@ public class CameraService { @@ -91,9 +99,9 @@ public class CameraService {
91 scheduledFuture.cancel(true); 99 scheduledFuture.cancel(true);
92 } 100 }
93 101
94 - if(videoIsOpen) 102 + if(OperatingData.cameraData.isVideoIsOpen())
95 { 103 {
96 - videoIsOpen = false; 104 + OperatingData.cameraData.setVideoIsOpen(false);
97 // 释放资源 105 // 释放资源
98 videoCapture.release(); 106 videoCapture.release();
99 } 107 }
@@ -105,9 +113,9 @@ public class CameraService { @@ -105,9 +113,9 @@ public class CameraService {
105 */ 113 */
106 public void clean() 114 public void clean()
107 { 115 {
108 - if(videoIsOpen) 116 + if(OperatingData.cameraData.isVideoIsOpen())
109 { 117 {
110 - videoIsOpen = false; 118 + OperatingData.cameraData.setVideoIsOpen(false);
111 // 释放资源 119 // 释放资源
112 videoCapture.release(); 120 videoCapture.release();
113 } 121 }
@@ -118,130 +126,76 @@ public class CameraService { @@ -118,130 +126,76 @@ public class CameraService {
118 return videoCapture; 126 return videoCapture;
119 } 127 }
120 128
121 - public Boolean getVideoIsOpen()  
122 - {  
123 - return videoIsOpen;  
124 - }  
125 -  
126 -  
127 - public static void main(String[] args) throws Exception{  
128 -  
129 - MulticastSocket socket = null;  
130 - try {  
131 - // 创建 MulticastSocket 对象  
132 - socket = new MulticastSocket();  
133 -  
134 - // 指定多播地址和端口  
135 - InetAddress group = InetAddress.getByName("239.255.255.250");  
136 - int port = 37020;  
137 129
138 - while (true)  
139 - {  
140 - // 创建要发送的消息  
141 - String message = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Probe><Uuid>B0F5E9C7-EBD5-4A03-99F7-B069B141C619</Uuid><Types>inquiry</Types></Probe>";  
142 - byte[] buffer = message.getBytes();  
143 -  
144 - // 创建 DatagramPacket 对象  
145 - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, port);  
146 -  
147 - // 发送数据包  
148 - socket.send(packet);  
149 -  
150 - Thread.sleep(10000);  
151 - } 130 + /**
  131 + * 读取网络摄像头
  132 + * @return
  133 + */
  134 + public VideoCapture readVideoCaptureForRtsp()
  135 + {
152 136
153 - } catch (IOException e) {  
154 - e.printStackTrace();  
155 - } finally {  
156 - if (socket != null) {  
157 - socket.close(); 137 + String rtspUrl = "rtsp://admin:Luhui586@"+ip+":554/h264/ch1/main/av_stream";
  138 + VideoCapture videoCapture = new VideoCapture(rtspUrl);
  139 + while (!videoCapture.isOpened())
  140 + {
  141 + try {
  142 + Thread.sleep(1000);
  143 + } catch (InterruptedException e) {
  144 + throw new RuntimeException(e);
158 } 145 }
159 } 146 }
  147 + return videoCapture;
160 } 148 }
161 149
162 - private static void sendclien()  
163 - {  
164 - try {  
165 - // 创建组播Socket  
166 - MulticastSocket multicastSocket = new MulticastSocket();  
167 -  
168 - // 创建组播地址  
169 - InetAddress group = InetAddress.getByName("239.255.255.250");  
170 - // 发送消息  
171 - String message = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Probe><Uuid>B0F5E9C7-EBD5-4A03-99F7-B069B141C619</Uuid><Types>inquiry</Types></Probe>";  
172 - byte[] buffer = message.getBytes();  
173 - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, 37020);  
174 - multicastSocket.send(packet);  
175 - // 关闭Socket  
176 - multicastSocket.close();  
177 - } catch (IOException e) {  
178 - e.printStackTrace();  
179 - }  
180 - }  
181 -  
182 - public static void onClien() 150 + /**
  151 + * 读取USB口的摄像头
  152 + * @return
  153 + */
  154 + public VideoCapture readVideoCaptureForUSB()
183 { 155 {
184 - DatagramSocket socket = null;  
185 - try {  
186 - // 创建 DatagramSocket 对象,监听指定的端口  
187 - socket = new DatagramSocket(37020);  
188 -  
189 - while (true) {  
190 - // 创建 DatagramPacket 对象,用于接收数据  
191 - byte[] buffer = new byte[1024];  
192 - DatagramPacket packet = new DatagramPacket(buffer, buffer.length);  
193 -  
194 - // 接收数据  
195 - socket.receive(packet);  
196 -  
197 - // 转换并打印接收到的数据  
198 - String received = new String(packet.getData(), 0, packet.getLength());  
199 - System.out.println("Received data: " + received); 156 + for(int i=0;i<10;i++)
  157 + {
  158 + logger.info("初始化摄像头");
  159 + try {
  160 + Thread.sleep(3000);
  161 + } catch (InterruptedException e) {
  162 + throw new RuntimeException(e);
200 } 163 }
201 - } catch (IOException e) {  
202 - e.printStackTrace();  
203 - } finally {  
204 - if (socket != null) {  
205 - socket.close(); 164 + VideoCapture videoCapture = new VideoCapture();
  165 + boolean isopen = videoCapture.open(i);
  166 + if(isopen)
  167 + {
  168 + logger.info("打开化摄像头"+i+"成功");
  169 + return videoCapture;
  170 + }else {
  171 + logger.info("打开化摄像头"+i+"失败");
  172 + }
  173 + if(null != videoCapture)
  174 + {
  175 + return videoCapture; //拿到的第一个摄像头返回
206 } 176 }
207 } 177 }
  178 + logger.info("未检测到USB摄像头!!!");
  179 + return null;
208 } 180 }
209 181
210 - public static void clien() 182 + /**
  183 + * 读取本地视频文件
  184 + * @return
  185 + */
  186 + private VideoCapture readVideoCaptureForFile()
211 { 187 {
212 - try {  
213 - // 创建组播Socket  
214 - MulticastSocket multicastSocket = new MulticastSocket(37020);  
215 -  
216 - // 加入组播地址  
217 - InetAddress group = InetAddress.getByName("239.255.255.250");  
218 - multicastSocket.joinGroup(group);  
219 -  
220 - boolean isip = true;  
221 - while (isip)  
222 - {  
223 - // 接收消息  
224 - byte[] buffer = new byte[1024];  
225 - DatagramPacket packet = new DatagramPacket(buffer, buffer.length);  
226 - multicastSocket.receive(packet);  
227 -  
228 - // 处理消息  
229 - String message = new String(packet.getData(), packet.getOffset(), packet.getLength());  
230 - System.out.println("Received: " + message);  
231 -  
232 - if(message.indexOf("ip")>=0)  
233 - {  
234 - isip = false;  
235 - }  
236 -  
237 - }  
238 -  
239 - // 关闭Socket  
240 - multicastSocket.leaveGroup(group);  
241 - multicastSocket.close();  
242 - } catch (IOException e) {  
243 - e.printStackTrace(); 188 + logger.info("未检测到摄像头{},尝试打开本地视频",MP4_FILE_PATH);
  189 + //如果找不到摄像头就找本地视频文件
  190 + File file = new File(MP4_FILE_PATH);
  191 + if(file.exists() && file.isFile())
  192 + {
  193 + VideoCapture videoCapture = new VideoCapture();
  194 + boolean isopen = videoCapture.open(MP4_FILE_PATH);
  195 + System.out.println(isopen);
  196 + return videoCapture;
244 } 197 }
  198 + return null;
245 } 199 }
246 200
247 } 201 }
1 -package com.zhonglai.luhui.smart.feeder.service; 1 +package com.zhonglai.luhui.smart.feeder.service.device;
2 2
3 3
4 import com.fazecast.jSerialComm.SerialPort; 4 import com.fazecast.jSerialComm.SerialPort;
@@ -9,6 +9,7 @@ import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter; @@ -9,6 +9,7 @@ import com.zhonglai.luhui.smart.feeder.dto.ConfigurationParameter;
9 import com.zhonglai.luhui.smart.feeder.dto.ModbusDto; 9 import com.zhonglai.luhui.smart.feeder.dto.ModbusDto;
10 import com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig; 10 import com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig;
11 import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto; 11 import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto;
  12 +import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService;
12 import org.slf4j.Logger; 13 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
14 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
  1 +package com.zhonglai.luhui.smart.feeder.service.device.handle;
  2 +
  3 +import com.ruoyi.common.utils.ByteUtil;
  4 +import com.sun.jna.Pointer;
  5 +import com.zhonglai.luhui.smart.feeder.service.device.CameraHandle;
  6 +import com.zhonglai.luhui.smart.feeder.service.device.CameraService;
  7 +import org.bytedeco.ffmpeg.global.avutil;
  8 +import org.bytedeco.javacv.*;
  9 +import org.bytedeco.opencv.opencv_core.IplImage;
  10 +import org.opencv.core.Mat;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +
  14 +import java.io.IOException;
  15 +import java.net.*;
  16 +import java.util.Enumeration;
  17 +import java.util.Random;
  18 +import java.util.UUID;
  19 +
  20 +public class CameraRtspHandle implements CameraHandle {
  21 + private static final Logger logger = LoggerFactory.getLogger(CameraRtspHandle.class);
  22 + private FFmpegFrameGrabber grabber;
  23 + private String ip = "192.168.0.198";
  24 + @Override
  25 + public void init() {
  26 + try {
  27 + FFmpegFrameGrabber.tryLoad();
  28 +
  29 + String rtspUrl = "rtsp://admin:Luhui586@"+ip+":554/h264/ch1/main/av_stream";
  30 + grabber = new FFmpegFrameGrabber(rtspUrl);
  31 +// grabber.setOption("framerate", "30"); // 设置帧率为30帧/秒
  32 + grabber.setVideoOption("fflags", "nobuffer");
  33 + grabber.setVideoOption("rtsp_transport", "tcp");
  34 + grabber.setOption("stimeout", "2000000");
  35 + avutil.av_log_set_level(avutil.AV_LOG_ERROR);
  36 + grabber.start();
  37 + } catch (Exception e) {
  38 + logger.error("摄像头初始化失败",e);
  39 + }
  40 + }
  41 +
  42 + @Override
  43 + public Mat getMat() {
  44 + return null;
  45 + }
  46 +
  47 + public static void main(String[] args) {
  48 +// CameraRtspHandle cameraRtspHandle = new CameraRtspHandle();
  49 +// cameraRtspHandle.init();
  50 +// FFmpegFrameGrabber grabber = cameraRtspHandle.grabber;
  51 +//
  52 +// CanvasFrame previewCanvas = new CanvasFrame("摄像头预览", CanvasFrame.getDefaultGamma() / grabber.getGamma());
  53 +// previewCanvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  54 +// previewCanvas.setAlwaysOnTop(true);
  55 +//
  56 +// // 创建一个FFmpegFrameFilter对象,用于图像压缩
  57 +// FFmpegFrameFilter filter = new FFmpegFrameFilter("scale=640:-1", grabber.getImageWidth(), grabber.getImageHeight());
  58 +// try {
  59 +// filter.start();
  60 +// } catch (FFmpegFrameFilter.Exception e) {
  61 +// throw new RuntimeException(e);
  62 +// }
  63 +//
  64 +//
  65 +// while (true)
  66 +// {
  67 +// logger.info("当前grabber状态:hasAudio {},hasVideo {},isCloseInputStream {},isDeinterlace {},isTriggerMode {}",grabber.hasAudio(),grabber.hasVideo(),grabber.isCloseInputStream(),grabber.isDeinterlace(),grabber.isTriggerMode());
  68 +// try {
  69 +// filter.push(grabber.grabImage());
  70 +// Frame filteredFrame = filter.pull();
  71 +// if(null != filteredFrame)
  72 +// {
  73 +// previewCanvas.showImage(filteredFrame);
  74 +// }
  75 +// } catch (FFmpegFrameGrabber.Exception e) {
  76 +// logger.info("无法显示");
  77 +// } catch (FFmpegFrameFilter.Exception e) {
  78 +// throw new RuntimeException(e);
  79 +// }
  80 +// }
  81 + // 创建UDP Socket
  82 + MulticastSocket socket = null;
  83 + try {
  84 + socket = new MulticastSocket (37020);
  85 + socket.setTimeToLive(1);
  86 +// socket.setSoTimeout(10000);
  87 + socket.joinGroup( InetAddress.getByName("239.255.255.250"));
  88 + } catch (SocketException e) {
  89 + throw new RuntimeException(e);
  90 + } catch (UnknownHostException e) {
  91 + throw new RuntimeException(e);
  92 + } catch (IOException e) {
  93 + throw new RuntimeException(e);
  94 + }
  95 + try {
  96 +
  97 + for (int i=0;i<3;i++)
  98 + {
  99 + UUID uuid = UUID.randomUUID();
  100 + String uuidString = uuid.toString().toUpperCase();
  101 + // 构造sadp请求数据包
  102 + String str = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Probe><Uuid>"+uuidString+"</Uuid><Types>inquiry</Types></Probe>";
  103 +
  104 + byte[] requestData = str.getBytes();
  105 + DatagramPacket requestPacket = new DatagramPacket(requestData, requestData.length, InetAddress.getByName("239.255.255.250"), 37020);
  106 +
  107 + Thread.sleep(1000);
  108 + // 发送请求数据包
  109 + socket.send(requestPacket);
  110 + }
  111 +
  112 + while (true)
  113 + {
  114 + // 接收响应数据包
  115 + byte[] responseData = new byte[4096];
  116 + DatagramPacket responsePacket = new DatagramPacket(responseData, responseData.length);
  117 + socket.receive(responsePacket);
  118 +
  119 + // 解析响应数据包
  120 + String response = new String(responsePacket.getData(), 0, responsePacket.getLength());
  121 + System.out.println("Response: " + response);
  122 + }
  123 +
  124 + } catch (Exception e) {
  125 + e.printStackTrace();
  126 + }finally {
  127 + try {
  128 + socket.leaveGroup( InetAddress.getByName("239.255.255.250"));
  129 + } catch (IOException e) {
  130 + throw new RuntimeException(e);
  131 + }
  132 + // 关闭Socket
  133 + socket.close();
  134 + }
  135 + }
  136 +
  137 + public static String formatUuid(String uuid) {
  138 + return uuid.substring(0, 8) + "-" +
  139 + uuid.substring(8, 12) + "-" +
  140 + uuid.substring(12, 16) + "-" +
  141 + uuid.substring(16, 20) + "-" +
  142 + uuid.substring(20);
  143 + }
  144 +
  145 + public static void sendudp()
  146 + {
  147 + try {
  148 + // 创建组播Socket
  149 + InetAddress group = InetAddress.getByName("239.255.255.250");
  150 + MulticastSocket socket = new MulticastSocket(37020);
  151 +
  152 + // 加入组播组
  153 + socket.joinGroup(group);
  154 +
  155 + while (socket.isConnected())
  156 + {
  157 + // 接收消息
  158 + byte[] buffer = new byte[4096];
  159 + DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
  160 + socket.receive(packet);
  161 + // 解析消息并处理
  162 + String message = new String(packet.getData(), 0, packet.getLength());
  163 + System.out.println("Received message: " + message);
  164 + }
  165 + // 退出组播组
  166 + socket.leaveGroup(group);
  167 +
  168 + // 关闭Socket
  169 + socket.close();
  170 + } catch (Exception e) {
  171 + e.printStackTrace();
  172 + }finally {
  173 +
  174 + }
  175 + }
  176 +
  177 + /**
  178 + * 生成UUID的方法
  179 + * @return 返回 UUID 字符串
  180 + */
  181 + public static String generateUUID() {
  182 + // 获取当前时间戳
  183 + long timeMillis = 1697789348000l;
  184 + // 获取机器MAC地址
  185 + String macAddress = "G24198441";
  186 + // 生成随机数
  187 + int randomInt = new Random().nextInt();
  188 + // 获取个人或组织的标识码(这里设为 001)
  189 + int nodeId = 001;
  190 + // 组合 UUID 字符串
  191 + String uuid = String.format("%016x", timeMillis) //
  192 + + String.format("%016x", randomInt) //
  193 + + String.format("%016x", nodeId) //
  194 + + macAddress;
  195 + // 返回 UUID 字符串
  196 + return uuid;
  197 + }
  198 +}
1 -# 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8064 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* sys: staticPath: "file:/opt/lh-smart-feeder/lh-smart-feeder/html/" srs_push_address: rtmp://119.23.218.181:21935/live/${mqtt.clientId} mp4_file_path: D:/lh-smart-feeder/2.mp4 # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # 数据源配置 spring: # autoconfigure: # exclude: org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: org.sqlite.JDBC druid: # 主库数据源 master: url: jdbc:sqlite:db/my.db username: password: # 从库数据源 slave: # 从数据源开关/默认关闭 enabled: false url: username: password: # 初始连接数 initialSize: 5 # 最小连接池数量 minIdle: 10 # 最大连接池数量 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最大生存的时间,单位是毫秒 maxEvictableIdleTimeMillis: 900000 # 配置检测连接是否有效 validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false webStatFilter: enabled: true statViewServlet: enabled: true # 设置白名单,不填则允许所有访问 allow: url-pattern: /druid/* # 控制台管理用户名和密码 login-username: ruoyi login-password: 123456 filter: stat: enabled: true # 慢SQL记录 log-slow-sql: true slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true mqtt: #链接地址 broker: tcp://175.24.61.68:1883 #唯一标识 clientId: 70094a59d1d991d #订阅的topic topics: PUT/+,GET_REQ/+, READ/+,POST_REQ/+ username: 12_ZNZY password: Luhui586 client: #客户端操作时间 operationTime: 10  
  1 +# 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8064 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* sys: staticPath: "file:/opt/lh-smart-feeder/lh-smart-feeder/html/" srs_push_address: rtmp://119.23.218.181:21935/live/${mqtt.clientId} mp4_file_path: D:/lh-smart-feeder/mp4/2.mp4 network_camera_ip: 192.168.0.198 # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # 数据源配置 spring: # autoconfigure: # exclude: org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: org.sqlite.JDBC druid: # 主库数据源 master: url: jdbc:sqlite:db/my.db username: password: # 从库数据源 slave: # 从数据源开关/默认关闭 enabled: false url: username: password: # 初始连接数 initialSize: 5 # 最小连接池数量 minIdle: 10 # 最大连接池数量 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最大生存的时间,单位是毫秒 maxEvictableIdleTimeMillis: 900000 # 配置检测连接是否有效 validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false webStatFilter: enabled: true statViewServlet: enabled: true # 设置白名单,不填则允许所有访问 allow: url-pattern: /druid/* # 控制台管理用户名和密码 login-username: ruoyi login-password: 123456 filter: stat: enabled: true # 慢SQL记录 log-slow-sql: true slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true mqtt: #链接地址 broker: tcp://175.24.61.68:1883 #唯一标识 clientId: 70094a59d1d991d #订阅的topic topics: PUT/+,GET_REQ/+, READ/+,POST_REQ/+ username: 12_ZNZY password: Luhui586 client: #客户端操作时间 operationTime: 10