作者 钟来

模块整理

1 -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-openai # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8062 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 # Spring配置 spring: # 模板引擎 thymeleaf: mode: HTML encoding: utf-8 # 禁用缓存 cache: false prefix: classpath:/static/ suffix: .html # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /register,/captchaImage,/getCacheObject,/v2/api-docs domainname: http://120.79.198.245:8062  
  1 +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: uploadPath # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 captchaType: math token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-openai # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8063 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 # Spring配置 spring: # 模板引擎 thymeleaf: mode: HTML encoding: utf-8 # 禁用缓存 cache: false prefix: classpath:/static/ suffix: .html # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /register,/captchaImage,/getCacheObject,/v2/api-docs domainname: http://120.79.198.245:8062
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <modelVersion>4.0.0</modelVersion>
  6 + <parent>
  7 + <groupId>com.zhonglai.luhui</groupId>
  8 + <artifactId>lh-modules</artifactId>
  9 + <version>1.0-SNAPSHOT</version>
  10 + </parent>
  11 +
  12 + <artifactId>lh-smart-feeder</artifactId>
  13 +
  14 + <properties>
  15 + <maven.compiler.source>8</maven.compiler.source>
  16 + <maven.compiler.target>8</maven.compiler.target>
  17 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  18 + </properties>
  19 + <dependencies>
  20 +
  21 + <dependency>
  22 + <groupId>com.zhonglai.luhui</groupId>
  23 + <artifactId>ruoyi-framework</artifactId>
  24 + <exclusions>
  25 + <exclusion>
  26 + <groupId>org.springframework.boot</groupId>
  27 + <artifactId>spring-boot-devtools</artifactId>
  28 + </exclusion>
  29 + </exclusions>
  30 + </dependency>
  31 + <dependency>
  32 + <groupId>org.aspectj</groupId>
  33 + <artifactId>aspectjweaver</artifactId>
  34 + </dependency>
  35 + <dependency>
  36 + <groupId>org.aspectj</groupId>
  37 + <artifactId>aspectjrt</artifactId>
  38 + </dependency>
  39 +
  40 +
  41 + <!-- OpenCV -->
  42 + <dependency>
  43 + <groupId>org</groupId>
  44 + <artifactId>opencv</artifactId>
  45 + <version>4.5.1</version>
  46 + <scope>system</scope>
  47 + <systemPath>${project.basedir}\src\main\resources\lib\opencv-451.jar</systemPath>
  48 + </dependency>
  49 +
  50 + <!-- 视频处理库 -->
  51 + <!-- https://mvnrepository.com/artifact/org.bytedeco/javacv-platform -->
  52 + <dependency>
  53 + <groupId>org.bytedeco</groupId>
  54 + <artifactId>javacv-platform</artifactId>
  55 + <version>1.5.4</version>
  56 + </dependency>
  57 +
  58 + </dependencies>
  59 +</project>
  1 +package com.zhonglai.luhui.smart.feeder;
  2 +
  3 +import com.zhonglai.luhui.smart.feeder.config.OpenCVConfig;
  4 +import org.springframework.boot.SpringApplication;
  5 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  6 +
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  10 +import org.springframework.context.annotation.ComponentScan;
  11 +import org.springframework.scheduling.annotation.EnableScheduling;
  12 +
  13 +import java.io.*;
  14 +import java.net.URL;
  15 +
  16 +@ComponentScan(basePackages = {
  17 + "com.ruoyi.common",
  18 + "com.ruoyi.framework",
  19 +}
  20 +)
  21 +@EnableScheduling
  22 +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class})
  23 +public class Main {
  24 + private static final Logger logger = LoggerFactory.getLogger(Main.class);
  25 +
  26 + public static void main(String[] args) {
  27 + OpenCVConfig.loadOpenCv(args);
  28 + SpringApplication.run(Main.class,args);
  29 + }
  30 +}
  1 +package com.zhonglai.luhui.smart.feeder.config;
  2 +
  3 +import com.zhonglai.luhui.smart.feeder.Main;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +
  7 +import java.io.File;
  8 +import java.net.URL;
  9 +
  10 +public class OpenCVConfig {
  11 + private static final Logger logger = LoggerFactory.getLogger(Main.class);
  12 + public static void loadOpenCv(String[] args)
  13 + {
  14 + String fileName = "dll/x64/opencv_java451.dll";
  15 + URL url = ClassLoader.getSystemResource("dll/x64/opencv_java451.dll");
  16 + if(null != url)
  17 + {
  18 + fileName = url.getPath();
  19 + }
  20 + if(null != args && args.length>=1)
  21 + {
  22 + fileName = args[0];
  23 + }
  24 + String path = new File(fileName).getAbsolutePath();
  25 + logger.info("加载:"+path);
  26 + System.load(path);
  27 + }
  28 +}
  1 +package com.zhonglai.luhui.smart.feeder.service;
  2 +
  3 +import com.zhonglai.luhui.smart.feeder.config.OpenCVConfig;
  4 +import com.zhonglai.luhui.smart.feeder.util.OpenCVUtils;
  5 +import org.opencv.core.Core;
  6 +import org.opencv.core.Mat;
  7 +import org.opencv.videoio.VideoCapture;
  8 +import org.opencv.imgproc.Imgproc;
  9 +import org.opencv.core.MatOfPoint;
  10 +import org.opencv.core.Scalar;
  11 +import org.opencv.core.CvType;
  12 +import org.opencv.core.Rect;
  13 +
  14 +import javax.swing.*;
  15 +import java.awt.image.BufferedImage;
  16 +import java.util.ArrayList;
  17 +import java.util.List;
  18 +
  19 +public class OpenCVService {
  20 + public static void main(String[] args) {
  21 + OpenCVConfig.loadOpenCv(args);
  22 + readVideoCaptureForVideo("C:/Users/123/Pictures/图片识别/6月30日.mp4");
  23 + }
  24 + public static void readVideoCaptureForVideo(String videoPath)
  25 + {
  26 + // 创建VideoCapture对象
  27 + VideoCapture videoCapture = new VideoCapture();
  28 + boolean isopen = videoCapture.open(videoPath);
  29 + System.out.println(isopen);
  30 + // 检查视频是否成功打开
  31 + if (!videoCapture.isOpened()) {
  32 + System.out.println("无法打开视频文件");
  33 + return;
  34 + }
  35 + // 背景帧
  36 + Mat backgroundFrame = new Mat();
  37 +
  38 + // 初始阈值范围
  39 + double minAreaThreshold = Double.MAX_VALUE;
  40 + double maxAreaThreshold = 0;
  41 +
  42 + // 逐帧处理视频
  43 + Mat frame = new Mat();
  44 + while (videoCapture.read(frame)) {
  45 + // 背景差分
  46 + Mat diffFrame = new Mat();
  47 + Core.absdiff(frame, backgroundFrame, diffFrame);
  48 +
  49 + // 灰度转换
  50 + Mat grayFrame = new Mat();
  51 + Imgproc.cvtColor(diffFrame, grayFrame, Imgproc.COLOR_BGR2GRAY);
  52 +
  53 + // 阈值处理
  54 + Mat thresholdFrame = new Mat();
  55 + Imgproc.threshold(grayFrame, thresholdFrame, 30, 255, Imgproc.THRESH_BINARY);
  56 +
  57 + // 边缘检测
  58 + Mat edges = new Mat();
  59 + Imgproc.Canny(thresholdFrame, edges, 100, 200);
  60 +
  61 + // 轮廓检测
  62 + List<MatOfPoint> contours = new ArrayList<>();
  63 + Mat hierarchy = new Mat();
  64 + Imgproc.findContours(edges, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
  65 +
  66 + // 更新阈值范围
  67 + for (MatOfPoint contour : contours) {
  68 + double area = Imgproc.contourArea(contour);
  69 + if (area > maxAreaThreshold) {
  70 + maxAreaThreshold = area;
  71 + }
  72 + if (area < minAreaThreshold) {
  73 + minAreaThreshold = area;
  74 + }
  75 + }
  76 +
  77 + // 根据阈值范围选择适当的阈值
  78 + double thresholdValue = (maxAreaThreshold + minAreaThreshold) / 2.0;
  79 +
  80 + // 绘制轮廓
  81 + Mat contourImage = new Mat(frame.size(), CvType.CV_8UC3, new Scalar(0, 0, 0));
  82 + Imgproc.drawContours(contourImage, contours, -1, new Scalar(0, 255, 0), 2);
  83 +
  84 + // 提取鱼群区域
  85 + for (MatOfPoint contour : contours) {
  86 + double area = Imgproc.contourArea(contour);
  87 + if (area > thresholdValue) {
  88 + // 对于满足面积阈值的轮廓,可以进一步处理或分析
  89 + // 例如,计算鱼群数量、中心位置等信息
  90 + // ...
  91 +
  92 + // 在原图上绘制鱼群区域
  93 + Rect boundingRect = Imgproc.boundingRect(contour);
  94 + Imgproc.rectangle(frame, boundingRect.tl(), boundingRect.br(), new Scalar(0, 255, 0), 2);
  95 + }
  96 + }
  97 + // 重置阈值范围
  98 + minAreaThreshold = Double.MAX_VALUE;
  99 + maxAreaThreshold = 0;
  100 +
  101 + // 在图像上显示结果
  102 + displayImage(frame);
  103 + }
  104 +
  105 + }
  106 +
  107 + // 显示图像
  108 + private static void displayImage(Mat image) {
  109 + // 将Mat图像转换为BufferedImage
  110 + BufferedImage bufferedImage = OpenCVUtils.matToBufferedImage(image);
  111 +
  112 + // 在标签上显示图像
  113 + new ImageIcon(bufferedImage);
  114 +
  115 + // 更新窗口
  116 + }
  117 +}
  1 +package com.zhonglai.luhui.smart.feeder.util;
  2 +
  3 +import org.opencv.core.*;
  4 +import org.opencv.imgcodecs.Imgcodecs;
  5 +import org.opencv.imgproc.Imgproc;
  6 +
  7 +import javax.imageio.ImageIO;
  8 +import java.awt.image.BufferedImage;
  9 +import java.io.ByteArrayInputStream;
  10 +import java.io.ByteArrayOutputStream;
  11 +import java.io.IOException;
  12 +
  13 +public class OpenCVUtils {
  14 + // 将Mat图像转换为BufferedImage
  15 + public static BufferedImage matToBufferedImage(Mat mat) {
  16 + MatOfByte matOfByte = new MatOfByte();
  17 + Imgcodecs.imencode(".jpg", mat, matOfByte);
  18 +
  19 + try {
  20 + byte[] byteArray = matOfByte.toArray();
  21 + ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
  22 + return ImageIO.read(bis);
  23 + } catch (IOException e) {
  24 + e.printStackTrace();
  25 + }
  26 +
  27 + return null;
  28 + }
  29 +
  30 + // 将BufferedImage图像转换为Mat
  31 + public static Mat bufferedImageToMat(BufferedImage image) {
  32 + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  33 + try {
  34 + ImageIO.write(image, "jpg", byteArrayOutputStream);
  35 + byteArrayOutputStream.flush();
  36 + byte[] byteArray = byteArrayOutputStream.toByteArray();
  37 + byteArrayOutputStream.close();
  38 + return Imgcodecs.imdecode(new MatOfByte(byteArray), Imgcodecs.IMREAD_UNCHANGED);
  39 + } catch (IOException e) {
  40 + e.printStackTrace();
  41 + }
  42 +
  43 + return null;
  44 + }
  45 +
  46 + // 调整图像大小
  47 + public static Mat resize(Mat image, int width, int height) {
  48 + Mat resizedImage = new Mat();
  49 + Size newSize = new Size(width, height);
  50 + Imgproc.resize(image, resizedImage, newSize);
  51 + return resizedImage;
  52 + }
  53 +
  54 + // 图像灰度化
  55 + public static Mat convertToGray(Mat image) {
  56 + Mat grayImage = new Mat();
  57 + Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_BGR2GRAY);
  58 + return grayImage;
  59 + }
  60 +
  61 + // 示例使用
  62 + public static void main(String[] args) {
  63 + // 加载OpenCV库
  64 + System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  65 +
  66 + // 读取图像
  67 + Mat image = Imgcodecs.imread("path_to_your_image_file");
  68 +
  69 + // 将Mat图像转换为BufferedImage
  70 + BufferedImage bufferedImage = matToBufferedImage(image);
  71 +
  72 + // 将BufferedImage图像转换为Mat
  73 + Mat matImage = bufferedImageToMat(bufferedImage);
  74 +
  75 + // 调整图像大小
  76 + int newWidth = 640;
  77 + int newHeight = 480;
  78 + Mat resizedImage = resize(matImage, newWidth, newHeight);
  79 +
  80 + // 图像灰度化
  81 + Mat grayImage = convertToGray(resizedImage);
  82 +
  83 + // 在这里对处理后的图像进行操作或显示
  84 + // ...
  85 + }
  86 +}
  1 +package com.zhonglai.luhui.smart.feeder.util;
  2 +
  3 +import com.zhonglai.luhui.smart.feeder.config.OpenCVConfig;
  4 +import org.bytedeco.javacv.FFmpegFrameGrabber;
  5 +import org.bytedeco.javacv.Frame;
  6 +import org.bytedeco.javacv.Java2DFrameConverter;
  7 +
  8 +import javax.imageio.ImageIO;
  9 +import java.awt.*;
  10 +import java.awt.image.BufferedImage;
  11 +import java.io.File;
  12 +
  13 +public class VideoUtil {
  14 + /**
  15 + * 获取指定视频的帧并保存为图片至指定目录
  16 + * @param file 源视频文件
  17 + * @param framefile 截取帧的图片存放路径
  18 + * @throws Exception
  19 + */
  20 + public static void fetchPic(File file, String framefile, int second) throws Exception{
  21 + FFmpegFrameGrabber ff = new FFmpegFrameGrabber(file);
  22 + ff.start();
  23 + int lenght = ff.getLengthInAudioFrames();
  24 + System.out.println(ff.getFrameRate());
  25 +
  26 + File pathFile = new File(framefile);
  27 + if( !pathFile.exists())
  28 + {
  29 + pathFile.mkdirs();
  30 + }
  31 +
  32 + int i = 0;
  33 + Frame frame = null;
  34 + while (i < lenght) {
  35 + frame = ff.grabImage();
  36 + if (i>=(int) (ff.getFrameRate()*second)&&frame.image != null) {
  37 + System.out.print(i+",");
  38 + if(frame!=null&&frame.image!=null) {
  39 + System.out.println(i);
  40 + writeToFile(framefile,frame, i);
  41 + }
  42 + second++;
  43 + }
  44 + i++;
  45 + }
  46 + ff.stop();
  47 + }
  48 +
  49 + public static void writeToFile(String framefile,Frame frame,int second){
  50 + File targetFile = new File(framefile+second+".jpg");
  51 + String imgSuffix = "jpg";
  52 +
  53 + Java2DFrameConverter converter =new Java2DFrameConverter();
  54 + BufferedImage srcBi =converter.getBufferedImage(frame);
  55 + int owidth = srcBi.getWidth();
  56 + int oheight = srcBi.getHeight();
  57 + // 对截取的帧进行等比例缩放
  58 + int width = 800;
  59 + int height = (int) (((double) width / owidth) * oheight);
  60 + BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
  61 + bi.getGraphics().drawImage(srcBi.getScaledInstance(width, height, Image.SCALE_SMOOTH),0, 0, null);
  62 + try {
  63 + ImageIO.write(bi, imgSuffix, targetFile);
  64 + }catch (Exception e) {
  65 + e.printStackTrace();
  66 + }
  67 + }
  68 +
  69 +
  70 + /**
  71 + * 获取视频时长,单位为秒
  72 + * @param file
  73 + * @return 时长(s)
  74 + */
  75 + public static Long getVideoTime(File file){
  76 + Long times = 0L;
  77 + try {
  78 + FFmpegFrameGrabber ff = new FFmpegFrameGrabber(file);
  79 + ff.start();
  80 + times = ff.getLengthInTime()/(1000*1000);
  81 + ff.stop();
  82 + } catch (Exception e) {
  83 + e.printStackTrace();
  84 + }
  85 + return times;
  86 + }
  87 +
  88 + public static void main(String[] args){
  89 + try {
  90 + OpenCVConfig.loadOpenCv(args);
  91 + File file = new File("C:\\Users\\123\\Pictures\\图片识别\\20210107_100743.mp4");
  92 + VideoUtil.fetchPic(file,"C:\\Users\\123\\Pictures\\图片识别\\1\\",100);
  93 + System.out.println(VideoUtil.getVideoTime(file));
  94 + } catch (Exception e) {
  95 + e.printStackTrace();
  96 + }
  97 + }
  98 +}
  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/*
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 <module>lh-login</module> 23 <module>lh-login</module>
24 <module>lh-chatgpt-api</module> 24 <module>lh-chatgpt-api</module>
25 <module>lh-runingfish</module> 25 <module>lh-runingfish</module>
  26 + <module>lh-smart-feeder</module>
26 </modules> 27 </modules>
27 28
28 <properties> 29 <properties>