正在显示
9 个修改的文件
包含
165 行增加
和
58 行删除
| 1 | package com.zhonglai.luhui.smart.feeder.config.manager; | 1 | package com.zhonglai.luhui.smart.feeder.config.manager; |
| 2 | 2 | ||
| 3 | -import com.zhonglai.luhui.smart.feeder.service.DeviceService; | 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.SerialPortService; |
| 6 | import com.zhonglai.luhui.smart.feeder.service.TerminalService; | 6 | import com.zhonglai.luhui.smart.feeder.service.TerminalService; |
| @@ -29,6 +29,9 @@ public class ShutdownManager | @@ -29,6 +29,9 @@ public class ShutdownManager | ||
| 29 | 29 | ||
| 30 | @Autowired | 30 | @Autowired |
| 31 | private TerminalService terminalService; | 31 | private TerminalService terminalService; |
| 32 | + @Autowired | ||
| 33 | + private SrsService srsService; | ||
| 34 | + | ||
| 32 | 35 | ||
| 33 | @PreDestroy | 36 | @PreDestroy |
| 34 | public void destroy() | 37 | public void destroy() |
| @@ -36,6 +39,7 @@ public class ShutdownManager | @@ -36,6 +39,7 @@ public class ShutdownManager | ||
| 36 | terminalService.close(); | 39 | terminalService.close(); |
| 37 | serialPortService.close(); | 40 | serialPortService.close(); |
| 38 | ehCacheService.shutdown(); | 41 | ehCacheService.shutdown(); |
| 42 | + srsService.stop(); | ||
| 39 | shutdownAsyncManager(); | 43 | shutdownAsyncManager(); |
| 40 | } | 44 | } |
| 41 | 45 |
| @@ -7,13 +7,21 @@ import java.io.Serializable; | @@ -7,13 +7,21 @@ import java.io.Serializable; | ||
| 7 | 7 | ||
| 8 | public class VeiwDto implements Serializable { | 8 | public class VeiwDto implements Serializable { |
| 9 | private static final long serialVersionUID = -6059514681715227839L; | 9 | private static final long serialVersionUID = -6059514681715227839L; |
| 10 | - private Mat frame; //原始图像 | ||
| 11 | - private Mat binaryImage; //临时图像 | ||
| 12 | private Integer size; //面积大小 | 10 | private Integer size; //面积大小 |
| 13 | private Double absValue; //变化的斜率 | 11 | private Double absValue; //变化的斜率 |
| 14 | 12 | ||
| 15 | private Integer push_camera; | 13 | private Integer push_camera; |
| 16 | 14 | ||
| 15 | + private Boolean isText; | ||
| 16 | + | ||
| 17 | + public Boolean getText() { | ||
| 18 | + return isText; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public void setText(Boolean text) { | ||
| 22 | + isText = text; | ||
| 23 | + } | ||
| 24 | + | ||
| 17 | public Integer getPush_camera() { | 25 | public Integer getPush_camera() { |
| 18 | return push_camera; | 26 | return push_camera; |
| 19 | } | 27 | } |
| @@ -22,20 +30,11 @@ public class VeiwDto implements Serializable { | @@ -22,20 +30,11 @@ public class VeiwDto implements Serializable { | ||
| 22 | this.push_camera = push_camera; | 30 | this.push_camera = push_camera; |
| 23 | } | 31 | } |
| 24 | 32 | ||
| 25 | - public VeiwDto(Mat frame, Integer size) { | ||
| 26 | - this.frame = frame; | ||
| 27 | - this.size = size; | ||
| 28 | - } | ||
| 29 | - | ||
| 30 | - public VeiwDto(Mat frame, Mat binaryImage, Integer size) { | ||
| 31 | - this.frame = frame; | ||
| 32 | - this.binaryImage = binaryImage; | 33 | + public VeiwDto(Integer size) { |
| 33 | this.size = size; | 34 | this.size = size; |
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | - public VeiwDto(Mat frame, Mat binaryImage, Integer size, Double absValue) { | ||
| 37 | - this.frame = frame; | ||
| 38 | - this.binaryImage = binaryImage; | 37 | + public VeiwDto( Integer size, Double absValue) { |
| 39 | this.size = size; | 38 | this.size = size; |
| 40 | this.absValue = absValue; | 39 | this.absValue = absValue; |
| 41 | } | 40 | } |
| @@ -51,22 +50,6 @@ public class VeiwDto implements Serializable { | @@ -51,22 +50,6 @@ public class VeiwDto implements Serializable { | ||
| 51 | public VeiwDto() { | 50 | public VeiwDto() { |
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | - public Mat getFrame() { | ||
| 55 | - return frame; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - public void setFrame(Mat frame) { | ||
| 59 | - this.frame = frame; | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - public Mat getBinaryImage() { | ||
| 63 | - return binaryImage; | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - public void setBinaryImage(Mat binaryImage) { | ||
| 67 | - this.binaryImage = binaryImage; | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | public Integer getSize() { | 53 | public Integer getSize() { |
| 71 | return size; | 54 | return size; |
| 72 | } | 55 | } |
| @@ -98,6 +98,8 @@ public class OpenCVUtil { | @@ -98,6 +98,8 @@ public class OpenCVUtil { | ||
| 98 | Mat extractedImage = new Mat(); | 98 | Mat extractedImage = new Mat(); |
| 99 | Core.bitwise_and(frame, extractedRegion, extractedImage); | 99 | Core.bitwise_and(frame, extractedRegion, extractedImage); |
| 100 | 100 | ||
| 101 | + extractedRegion.release(); //释放内存 | ||
| 102 | + | ||
| 101 | return extractedImage; | 103 | return extractedImage; |
| 102 | } | 104 | } |
| 103 | 105 |
| 1 | +package com.zhonglai.luhui.smart.feeder.service; | ||
| 2 | + | ||
| 3 | +import org.bytedeco.javacv.CanvasFrame; | ||
| 4 | +import org.bytedeco.javacv.FFmpegFrameGrabber; | ||
| 5 | +import org.bytedeco.javacv.Frame; | ||
| 6 | +import org.bytedeco.javacv.FrameGrabber; | ||
| 7 | + | ||
| 8 | +public class FFmCameraService { | ||
| 9 | + public static void main(String[] args) { | ||
| 10 | +// int maxCameraIndex = 10; // 最大尝试的摄像头索引数量 | ||
| 11 | +// for (int cameraIndex = 0; cameraIndex < maxCameraIndex; ++cameraIndex) { | ||
| 12 | +// try { | ||
| 13 | +// FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(cameraIndex); | ||
| 14 | +// grabber.start(); // 尝试开始,如果失败将抛出异常 | ||
| 15 | +// try { | ||
| 16 | +// // 创建一个窗口用于显示摄像头的视频流 | ||
| 17 | +// CanvasFrame frame = new CanvasFrame("Webcam"); | ||
| 18 | +// | ||
| 19 | +// // 判断窗口是否关闭 | ||
| 20 | +// while (frame.isVisible()) { | ||
| 21 | +// // 抓取一帧视频并将其放在窗口上显示,该操作会阻塞程序,直到下一帧视频可用 | ||
| 22 | +// Frame grabbedFrame = grabber.grab(); | ||
| 23 | +// frame.showImage(grabbedFrame); | ||
| 24 | +// } | ||
| 25 | +// | ||
| 26 | +// // 关闭窗口 | ||
| 27 | +// frame.dispose(); | ||
| 28 | +// } finally { | ||
| 29 | +// // 停止抓取 | ||
| 30 | +// grabber.stop(); | ||
| 31 | +// } | ||
| 32 | +// break; // 如果找到了摄像头并成功打开,就结束循环 | ||
| 33 | +// } catch (FrameGrabber.Exception e) { | ||
| 34 | +// // 如果失败,就继续尝试下一个摄像头 | ||
| 35 | +// System.out.println("Failed to start the camera with device index: " + cameraIndex); | ||
| 36 | +// } | ||
| 37 | +// } | ||
| 38 | + } | ||
| 39 | +} |
| @@ -6,6 +6,8 @@ import com.zhonglai.luhui.smart.feeder.dto.VeiwDto; | @@ -6,6 +6,8 @@ import com.zhonglai.luhui.smart.feeder.dto.VeiwDto; | ||
| 6 | import com.zhonglai.luhui.smart.feeder.dto.VeiwType; | 6 | import com.zhonglai.luhui.smart.feeder.dto.VeiwType; |
| 7 | import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil; | 7 | import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil; |
| 8 | import com.zhonglai.luhui.smart.feeder.service.impl.HtmllVeiwServiceImpl; | 8 | import com.zhonglai.luhui.smart.feeder.service.impl.HtmllVeiwServiceImpl; |
| 9 | +import org.bytedeco.javacv.Frame; | ||
| 10 | +import org.bytedeco.javacv.OpenCVFrameConverter; | ||
| 9 | import org.opencv.core.Mat; | 11 | import org.opencv.core.Mat; |
| 10 | import org.opencv.core.MatOfPoint; | 12 | import org.opencv.core.MatOfPoint; |
| 11 | import org.opencv.core.Scalar; | 13 | import org.opencv.core.Scalar; |
| @@ -42,10 +44,17 @@ public class FishGroupImageRecognitionService { | @@ -42,10 +44,17 @@ public class FishGroupImageRecognitionService { | ||
| 42 | @Autowired | 44 | @Autowired |
| 43 | private DeviceService deviceService; | 45 | private DeviceService deviceService; |
| 44 | 46 | ||
| 47 | + @Autowired | ||
| 48 | + private SrsService srsService; | ||
| 49 | + | ||
| 45 | private static Boolean isRun = false; | 50 | private static Boolean isRun = false; |
| 46 | 51 | ||
| 47 | private VeiwDto veiwDto; | 52 | private VeiwDto veiwDto; |
| 48 | 53 | ||
| 54 | + private Boolean isText = false; | ||
| 55 | + | ||
| 56 | + private MatOfPoint largestContour; | ||
| 57 | + | ||
| 49 | public void run() | 58 | public void run() |
| 50 | { | 59 | { |
| 51 | scheduledExecutorService.scheduleWithFixedDelay(() -> { | 60 | scheduledExecutorService.scheduleWithFixedDelay(() -> { |
| @@ -91,14 +100,21 @@ public class FishGroupImageRecognitionService { | @@ -91,14 +100,21 @@ public class FishGroupImageRecognitionService { | ||
| 91 | double maxArea = 0; | 100 | double maxArea = 0; |
| 92 | int maxAreaIndex = -1; | 101 | int maxAreaIndex = -1; |
| 93 | for (int i = 0; i < contours.size(); i++) { | 102 | for (int i = 0; i < contours.size(); i++) { |
| 94 | - double area = Imgproc.contourArea(contours.get(i)); | 103 | + MatOfPoint matOfPoint = contours.get(i); |
| 104 | + double area = Imgproc.contourArea(matOfPoint); | ||
| 95 | if (area > maxArea) { | 105 | if (area > maxArea) { |
| 96 | maxArea = area; | 106 | maxArea = area; |
| 97 | maxAreaIndex = i; | 107 | maxAreaIndex = i; |
| 108 | + }else{ | ||
| 109 | + matOfPoint.release(); | ||
| 98 | } | 110 | } |
| 99 | } | 111 | } |
| 100 | // 获取最大区域的轮廓 | 112 | // 获取最大区域的轮廓 |
| 101 | MatOfPoint largestContour = contours.get(maxAreaIndex); | 113 | MatOfPoint largestContour = contours.get(maxAreaIndex); |
| 114 | + | ||
| 115 | + firstBinaryImage.release(); | ||
| 116 | + hierarchy.release(); | ||
| 117 | + | ||
| 102 | return largestContour; | 118 | return largestContour; |
| 103 | } | 119 | } |
| 104 | 120 | ||
| @@ -116,7 +132,11 @@ public class FishGroupImageRecognitionService { | @@ -116,7 +132,11 @@ public class FishGroupImageRecognitionService { | ||
| 116 | } | 132 | } |
| 117 | logger.info("鱼群识别时检测摄像头"); | 133 | logger.info("鱼群识别时检测摄像头"); |
| 118 | // 获取水域轮廓 | 134 | // 获取水域轮廓 |
| 119 | - MatOfPoint largestContour = getDefaultMatOfPoint(previousFrame); | 135 | + if(null != largestContour) |
| 136 | + { | ||
| 137 | + largestContour.release(); | ||
| 138 | + } | ||
| 139 | + largestContour = getDefaultMatOfPoint(previousFrame); | ||
| 120 | 140 | ||
| 121 | Long time =66l; | 141 | Long time =66l; |
| 122 | if(null != configurationParameterService.getConfig(ConfigurationParameter.IdentificationFrequency)) | 142 | if(null != configurationParameterService.getConfig(ConfigurationParameter.IdentificationFrequency)) |
| @@ -124,10 +144,10 @@ public class FishGroupImageRecognitionService { | @@ -124,10 +144,10 @@ public class FishGroupImageRecognitionService { | ||
| 124 | time = (Long) configurationParameterService.getConfig(ConfigurationParameter.IdentificationFrequency); | 144 | time = (Long) configurationParameterService.getConfig(ConfigurationParameter.IdentificationFrequency); |
| 125 | } | 145 | } |
| 126 | // 逐帧处理视频 | 146 | // 逐帧处理视频 |
| 127 | - Mat frame = new Mat(); | ||
| 128 | scheduledExecutorService.scheduleWithFixedDelay(() -> { | 147 | scheduledExecutorService.scheduleWithFixedDelay(() -> { |
| 129 | try { | 148 | try { |
| 130 | Boolean fishGroupImageRecognition = ((Boolean)configurationParameterService.getConfig(ConfigurationParameter.FishGroupImageRecognition)); | 149 | Boolean fishGroupImageRecognition = ((Boolean)configurationParameterService.getConfig(ConfigurationParameter.FishGroupImageRecognition)); |
| 150 | + Mat frame = new Mat(); | ||
| 131 | Boolean isread = videoCapture.read(frame); | 151 | Boolean isread = videoCapture.read(frame); |
| 132 | logger.info("逐帧处理视频,开始处理的判断参数:鱼群图像识别是否开启 {}、摄像头是否可读取 {}",fishGroupImageRecognition,isread); | 152 | logger.info("逐帧处理视频,开始处理的判断参数:鱼群图像识别是否开启 {}、摄像头是否可读取 {}",fishGroupImageRecognition,isread); |
| 133 | if(!isread ) | 153 | if(!isread ) |
| @@ -142,8 +162,9 @@ public class FishGroupImageRecognitionService { | @@ -142,8 +162,9 @@ public class FishGroupImageRecognitionService { | ||
| 142 | 162 | ||
| 143 | } | 163 | } |
| 144 | if (fishGroupImageRecognition && isread) { | 164 | if (fishGroupImageRecognition && isread) { |
| 145 | - identify(frame,largestContour); | 165 | + identify(frame); |
| 146 | } | 166 | } |
| 167 | + frame.release(); | ||
| 147 | }catch (Exception e) | 168 | }catch (Exception e) |
| 148 | { | 169 | { |
| 149 | logger.error("识别错误",e); | 170 | logger.error("识别错误",e); |
| @@ -151,14 +172,18 @@ public class FishGroupImageRecognitionService { | @@ -151,14 +172,18 @@ public class FishGroupImageRecognitionService { | ||
| 151 | 172 | ||
| 152 | },0,time, TimeUnit.MILLISECONDS); | 173 | },0,time, TimeUnit.MILLISECONDS); |
| 153 | 174 | ||
| 175 | + previousFrame.release(); | ||
| 176 | + | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + public void setText(Boolean text) { | ||
| 180 | + isText = text; | ||
| 154 | } | 181 | } |
| 155 | 182 | ||
| 156 | /** | 183 | /** |
| 157 | * 识别 | 184 | * 识别 |
| 158 | - * @param frame | ||
| 159 | - * @param largestContour | ||
| 160 | */ | 185 | */ |
| 161 | - private void identify(Mat frame, MatOfPoint largestContour) | 186 | + private void identify(Mat frame) |
| 162 | { | 187 | { |
| 163 | //抠图 | 188 | //抠图 |
| 164 | Mat shuiyu = OpenCVUtil.matting(frame,largestContour); | 189 | Mat shuiyu = OpenCVUtil.matting(frame,largestContour); |
| @@ -177,18 +202,23 @@ public class FishGroupImageRecognitionService { | @@ -177,18 +202,23 @@ public class FishGroupImageRecognitionService { | ||
| 177 | // 在水域二值图像中找所有轮廓 | 202 | // 在水域二值图像中找所有轮廓 |
| 178 | Imgproc.findContours(binaryImage, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); | 203 | Imgproc.findContours(binaryImage, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); |
| 179 | 204 | ||
| 205 | + if(null != isText && isText) | ||
| 206 | + { | ||
| 207 | + //标注识别对象 | ||
| 208 | + Imgproc.drawContours(frame, contours, -1, new Scalar(0, 0, 255), 2); | ||
| 209 | + Imgproc.drawContours(frame, Arrays.asList(new MatOfPoint[]{largestContour}), 0, new Scalar(0, 255, 0), 2); | ||
| 210 | + } | ||
| 211 | + | ||
| 180 | //计算大小 | 212 | //计算大小 |
| 181 | double area = getArea(contours); | 213 | double area = getArea(contours); |
| 182 | 214 | ||
| 183 | - //标注识别对象 | ||
| 184 | - Imgproc.drawContours(frame, contours, -1, new Scalar(0, 0, 255), 2); | ||
| 185 | - Imgproc.drawContours(frame, Arrays.asList(new MatOfPoint[]{largestContour}), 0, new Scalar(0, 255, 0), 2); | ||
| 186 | - | ||
| 187 | //计算斜率 | 215 | //计算斜率 |
| 188 | double absValue = deviceService.controlDevice(area); | 216 | double absValue = deviceService.controlDevice(area); |
| 189 | configurationParameterService.setConfig(ConfigurationParameter.absValue,absValue); | 217 | configurationParameterService.setConfig(ConfigurationParameter.absValue,absValue); |
| 190 | 218 | ||
| 191 | - veiwDto = new VeiwDto(frame,binaryImage,new Double(area).intValue(),absValue); | 219 | + veiwDto = new VeiwDto(new Double(area).intValue(),absValue); |
| 220 | + | ||
| 221 | + srsService.timepush(frame,absValue); | ||
| 192 | 222 | ||
| 193 | // 显示图像 | 223 | // 显示图像 |
| 194 | logger.info("是否显示{},客户端数量{}",configurationParameterService.getConfig(ConfigurationParameter.ifVeiw),WebSocketClien.webSocketSet.size()); | 224 | logger.info("是否显示{},客户端数量{}",configurationParameterService.getConfig(ConfigurationParameter.ifVeiw),WebSocketClien.webSocketSet.size()); |
| @@ -198,6 +228,11 @@ public class FishGroupImageRecognitionService { | @@ -198,6 +228,11 @@ public class FishGroupImageRecognitionService { | ||
| 198 | { | 228 | { |
| 199 | new HtmllVeiwServiceImpl(configurationParameterService).veiw(veiwDto); | 229 | new HtmllVeiwServiceImpl(configurationParameterService).veiw(veiwDto); |
| 200 | } | 230 | } |
| 231 | + | ||
| 232 | + shuiyu.release(); | ||
| 233 | + gray.release(); | ||
| 234 | + hierarchy.release(); | ||
| 235 | + binaryImage.release(); | ||
| 201 | } | 236 | } |
| 202 | 237 | ||
| 203 | /** | 238 | /** |
| @@ -211,12 +246,15 @@ public class FishGroupImageRecognitionService { | @@ -211,12 +246,15 @@ public class FishGroupImageRecognitionService { | ||
| 211 | int maxAreaIndex = -1; | 246 | int maxAreaIndex = -1; |
| 212 | double allArea = 0; | 247 | double allArea = 0; |
| 213 | for (int i = 0; i < contours.size(); i++) { | 248 | for (int i = 0; i < contours.size(); i++) { |
| 214 | - double area = Imgproc.contourArea(contours.get(i)); | 249 | + MatOfPoint matOfPoint = contours.get(i); |
| 250 | + double area = Imgproc.contourArea(matOfPoint); | ||
| 215 | if (area > maxArea) { | 251 | if (area > maxArea) { |
| 216 | maxArea = area; | 252 | maxArea = area; |
| 217 | maxAreaIndex = i; | 253 | maxAreaIndex = i; |
| 218 | } | 254 | } |
| 219 | allArea += area; | 255 | allArea += area; |
| 256 | + | ||
| 257 | + matOfPoint.release(); | ||
| 220 | } | 258 | } |
| 221 | 259 | ||
| 222 | //删除最大 | 260 | //删除最大 |
| @@ -249,6 +287,9 @@ public class FishGroupImageRecognitionService { | @@ -249,6 +287,9 @@ public class FishGroupImageRecognitionService { | ||
| 249 | Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size((Integer) configurationParameterService.getConfig(ConfigurationParameter.kernelSize),(Integer) configurationParameterService.getConfig(ConfigurationParameter.kernelSize))); | 287 | Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size((Integer) configurationParameterService.getConfig(ConfigurationParameter.kernelSize),(Integer) configurationParameterService.getConfig(ConfigurationParameter.kernelSize))); |
| 250 | Imgproc.morphologyEx(binaryImage, binaryImage, Imgproc.MORPH_OPEN, kernel); | 288 | Imgproc.morphologyEx(binaryImage, binaryImage, Imgproc.MORPH_OPEN, kernel); |
| 251 | 289 | ||
| 290 | + grayImage.release(); | ||
| 291 | + kernel.release(); | ||
| 292 | + | ||
| 252 | return binaryImage; | 293 | return binaryImage; |
| 253 | } | 294 | } |
| 254 | 295 |
| @@ -35,6 +35,9 @@ public class MqttCallback implements MqttCallbackExtended { | @@ -35,6 +35,9 @@ public class MqttCallback implements MqttCallbackExtended { | ||
| 35 | @Autowired | 35 | @Autowired |
| 36 | private SrsService srsService; | 36 | private SrsService srsService; |
| 37 | 37 | ||
| 38 | + @Autowired | ||
| 39 | + private FishGroupImageRecognitionService fishGroupImageRecognitionService; | ||
| 40 | + | ||
| 38 | private MqttClient mqttclient; | 41 | private MqttClient mqttclient; |
| 39 | 42 | ||
| 40 | 43 | ||
| @@ -122,6 +125,7 @@ public class MqttCallback implements MqttCallbackExtended { | @@ -122,6 +125,7 @@ public class MqttCallback implements MqttCallbackExtended { | ||
| 122 | break; | 125 | break; |
| 123 | case 1: | 126 | case 1: |
| 124 | srsService.run(300); | 127 | srsService.run(300); |
| 128 | + fishGroupImageRecognitionService.setText(veiwDto.getText()); | ||
| 125 | break; | 129 | break; |
| 126 | } | 130 | } |
| 127 | } | 131 | } |
| @@ -57,16 +57,17 @@ public class SrsService { | @@ -57,16 +57,17 @@ public class SrsService { | ||
| 57 | endTime = DateUtils.getNowTimeMilly()+time; | 57 | endTime = DateUtils.getNowTimeMilly()+time; |
| 58 | if(!isPush) | 58 | if(!isPush) |
| 59 | { | 59 | { |
| 60 | - VeiwDto veiwDto = fishGroupImageRecognitionService.getVeiwDto(); | ||
| 61 | - init(veiwDto.getFrame().width(),veiwDto.getFrame().height()+200); | ||
| 62 | - scheduledExecutorService.schedule(() -> { | ||
| 63 | - while (endTime-DateUtils.getNowTimeMilly()>0) | ||
| 64 | - { | ||
| 65 | - Mat mat = drawChart(fishGroupImageRecognitionService.getVeiwDto().getFrame(),fishGroupImageRecognitionService.getVeiwDto().getAbsValue()); | ||
| 66 | - push(mat); | ||
| 67 | - } | ||
| 68 | - stop(); | ||
| 69 | - },1, TimeUnit.SECONDS); | 60 | + isPush = true; |
| 61 | + init(640,480+200); | ||
| 62 | +// scheduledExecutorService.schedule(() -> { | ||
| 63 | +// while (endTime-DateUtils.getNowTimeMilly()>0) | ||
| 64 | +// { | ||
| 65 | +// Mat mat = drawChart(fishGroupImageRecognitionService.getVeiwDto().getFrame(),fishGroupImageRecognitionService.getVeiwDto().getAbsValue()); | ||
| 66 | +// push(mat); | ||
| 67 | +// mat.release(); | ||
| 68 | +// } | ||
| 69 | +// stop(); | ||
| 70 | +// },1, TimeUnit.SECONDS); | ||
| 70 | } | 71 | } |
| 71 | } | 72 | } |
| 72 | public void stop() | 73 | public void stop() |
| @@ -76,6 +77,21 @@ public class SrsService { | @@ -76,6 +77,21 @@ public class SrsService { | ||
| 76 | close(); | 77 | close(); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 80 | + public void timepush(Mat frame,Double absValue) | ||
| 81 | + { | ||
| 82 | + if(isPush) | ||
| 83 | + { | ||
| 84 | + if(endTime-DateUtils.getNowTimeMilly()>0) | ||
| 85 | + { | ||
| 86 | + Mat mat = drawChart(frame,absValue); | ||
| 87 | + push(mat); | ||
| 88 | + mat.release(); | ||
| 89 | + }else { | ||
| 90 | + stop(); | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 79 | 95 | ||
| 80 | public SrsService init(int frameWidth,int frameHeight) throws Exception | 96 | public SrsService init(int frameWidth,int frameHeight) throws Exception |
| 81 | { | 97 | { |
| @@ -134,6 +150,21 @@ public class SrsService { | @@ -134,6 +150,21 @@ public class SrsService { | ||
| 134 | mats.add(src); | 150 | mats.add(src); |
| 135 | mats.add(curveArea); | 151 | mats.add(curveArea); |
| 136 | Core.vconcat(mats, pushmat); | 152 | Core.vconcat(mats, pushmat); |
| 153 | + | ||
| 154 | + // 文字位置 | ||
| 155 | + Point org = new Point(50, 50); | ||
| 156 | + // 字体类型 | ||
| 157 | + int fontFace = Imgproc.FONT_HERSHEY_SIMPLEX; | ||
| 158 | + // 字体比例 | ||
| 159 | + double fontScale = 1; | ||
| 160 | + // 文字颜色(黑色) | ||
| 161 | + Scalar color = new Scalar(139, 0, 139); | ||
| 162 | + // 添加文字 | ||
| 163 | + Imgproc.putText(pushmat, "area:"+area, org, fontFace, fontScale, color); | ||
| 164 | + | ||
| 165 | + curveArea.release(); | ||
| 166 | + curve.release(); | ||
| 167 | + | ||
| 137 | return pushmat; | 168 | return pushmat; |
| 138 | } | 169 | } |
| 139 | 170 | ||
| @@ -141,6 +172,7 @@ public class SrsService { | @@ -141,6 +172,7 @@ public class SrsService { | ||
| 141 | OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); | 172 | OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); |
| 142 | Frame frame = converter.convert(pushmat); | 173 | Frame frame = converter.convert(pushmat); |
| 143 | push(frame); | 174 | push(frame); |
| 175 | + pushmat.release(); | ||
| 144 | } | 176 | } |
| 145 | 177 | ||
| 146 | public void push(Frame frame) { | 178 | public void push(Frame frame) { |
| @@ -48,8 +48,10 @@ public class HtmllVeiwServiceImpl implements DisplayVeiwService { | @@ -48,8 +48,10 @@ public class HtmllVeiwServiceImpl implements DisplayVeiwService { | ||
| 48 | bufImage = ImageIO.read(in); | 48 | bufImage = ImageIO.read(in); |
| 49 | in.close(); | 49 | in.close(); |
| 50 | } catch (Exception e) { | 50 | } catch (Exception e) { |
| 51 | + mob.release(); | ||
| 51 | e.printStackTrace(); | 52 | e.printStackTrace(); |
| 52 | } | 53 | } |
| 54 | + mob.release(); | ||
| 53 | return bufImage; | 55 | return bufImage; |
| 54 | } | 56 | } |
| 55 | 57 | ||
| @@ -133,11 +135,11 @@ public class HtmllVeiwServiceImpl implements DisplayVeiwService { | @@ -133,11 +135,11 @@ public class HtmllVeiwServiceImpl implements DisplayVeiwService { | ||
| 133 | 135 | ||
| 134 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isFrame)) | 136 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isFrame)) |
| 135 | { | 137 | { |
| 136 | - webSocketVO.setFrame(matToString(veiwDto.getFrame(),"jpg")); | 138 | +// webSocketVO.setFrame(matToString(veiwDto.getFrame(),"jpg")); |
| 137 | } | 139 | } |
| 138 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isBinaryImage)) | 140 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isBinaryImage)) |
| 139 | { | 141 | { |
| 140 | - webSocketVO.setBinaryImage(matToString(veiwDto.getBinaryImage(),"jpg")); | 142 | +// webSocketVO.setBinaryImage(matToString(veiwDto.getBinaryImage(),"jpg")); |
| 141 | } | 143 | } |
| 142 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isSize)) | 144 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isSize)) |
| 143 | { | 145 | { |
| @@ -151,7 +153,7 @@ public class HtmllVeiwServiceImpl implements DisplayVeiwService { | @@ -151,7 +153,7 @@ public class HtmllVeiwServiceImpl implements DisplayVeiwService { | ||
| 151 | { | 153 | { |
| 152 | webSocketSever.sendWebSocketVO(webSocketVO); | 154 | webSocketSever.sendWebSocketVO(webSocketVO); |
| 153 | } | 155 | } |
| 154 | - } catch (IOException e) { | 156 | + } catch (Exception e) { |
| 155 | throw new RuntimeException(e); | 157 | throw new RuntimeException(e); |
| 156 | } | 158 | } |
| 157 | 159 |
| @@ -40,11 +40,11 @@ public class JFrameVeiwServiceImpl implements DisplayVeiwService { | @@ -40,11 +40,11 @@ public class JFrameVeiwServiceImpl implements DisplayVeiwService { | ||
| 40 | 40 | ||
| 41 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isBinaryImage)) | 41 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isBinaryImage)) |
| 42 | { | 42 | { |
| 43 | - fishRegionPanel.getLblImage().setIcon(new ImageIcon(convertMatToImage(veiwDto.getBinaryImage()))); | 43 | +// fishRegionPanel.getLblImage().setIcon(new ImageIcon(convertMatToImage(veiwDto.getBinaryImage()))); |
| 44 | } | 44 | } |
| 45 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isFrame)) | 45 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isFrame)) |
| 46 | { | 46 | { |
| 47 | - fishRegionPanel.getSrcImage().setIcon(new ImageIcon(convertMatToImage(veiwDto.getFrame()))); | 47 | +// fishRegionPanel.getSrcImage().setIcon(new ImageIcon(convertMatToImage(veiwDto.getFrame()))); |
| 48 | } | 48 | } |
| 49 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isSize)) | 49 | if((boolean)configurationParameterService.getConfig(ConfigurationParameter.VeiwDto_isSize)) |
| 50 | { | 50 | { |
-
请 注册 或 登录 后发表评论