lwhhszx 1 rok pred
rodič
commit
a0df7dfc29

BIN
image_1.png


BIN
image_10.png


BIN
image_11.png


BIN
image_12.png


BIN
image_13.png


BIN
image_14.png


BIN
image_15.png


BIN
image_16.png


BIN
image_17.png


BIN
image_18.png


BIN
image_19.png


BIN
image_2.png


BIN
image_20.png


BIN
image_21.png


BIN
image_22.png


BIN
image_23.png


BIN
image_24.png


BIN
image_25.png


BIN
image_26.png


BIN
image_27.png


BIN
image_28.png


BIN
image_29.png


BIN
image_3.png


BIN
image_30.png


BIN
image_31.png


BIN
image_32.png


BIN
image_33.png


BIN
image_34.png


BIN
image_35.png


BIN
image_36.png


BIN
image_4.png


BIN
image_5.png


BIN
image_6.png


BIN
image_7.png


BIN
image_8.png


BIN
image_9.png


+ 9 - 0
pom.xml

@@ -75,6 +75,15 @@
             <artifactId>dingtalk</artifactId>
             <version>1.4.78</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.openpnp</groupId>
+            <artifactId>opencv</artifactId>
+            <version>3.4.2-1</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 6 - 0
src/main/java/com/test/xiaoshi/test/XiaoshiTestApplication.java

@@ -3,11 +3,17 @@ package com.test.xiaoshi.test;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
 @SpringBootApplication
 public class XiaoshiTestApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(XiaoshiTestApplication.class, args);
+        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "后台程序已启动,请运行前台");
+
     }
 
 }

+ 112 - 0
src/main/java/com/test/xiaoshi/test/common/util/MatUtil.java

@@ -0,0 +1,112 @@
+package com.test.xiaoshi.test.common.util;
+
+import org.opencv.core.CvType;
+import org.opencv.core.Mat;
+import org.opencv.core.MatOfByte;
+import org.opencv.imgcodecs.Imgcodecs;
+
+
+import javax.imageio.ImageIO;
+import javax.xml.bind.DatatypeConverter;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+/**
+ * @author Tang_J on 2022/4/20 下午 02:00
+ * @Description TODO
+ **/
+public class MatUtil {
+
+
+
+    /**
+     * Mat 转换成 byte[]
+     *
+     * @param mat Mat对象
+     * @return byte[]
+     */
+    public static byte[] toByteArray(Mat mat) {
+        MatOfByte mob = new MatOfByte();
+        Imgcodecs.imencode(".jpg", mat, mob);
+        return mob.toArray();
+    }
+
+    /**
+     * byte[] 转 图片Base64
+     *
+     * @param bytes byte[]
+     * @return Base64
+     */
+    public static String byteArray2Base64(byte[] bytes) {
+        return DatatypeConverter.printBase64Binary(bytes);
+    }
+
+    /**
+     * Mat 转 图片Base64
+     *
+     * @param mat Mat
+     * @return 图片Base64
+     */
+    public static String mat2Base64(Mat mat) {
+        return byteArray2Base64(toByteArray(mat));
+    }
+
+    /**
+     * Mat 转换成 BufferedImage
+     *
+     * @param mat Mat
+     * @return BufferedImage
+     */
+    public static BufferedImage toBufferedImage(Mat mat) throws IOException {
+        byte[] buffer = toByteArray(mat);
+        ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
+        return ImageIO.read(inputStream);
+    }
+
+    /**
+     * Base64 转换成 Mat
+     *
+     * @param base64 图片Base64
+     * @return Mat
+     */
+
+
+    /**
+     * BufferedImage 转换成 Mat
+     *
+     * @param original 要转换的BufferedImage
+     * @param imgType  bufferedImage的类型 如 BufferedImage.TYPE_3BYTE_BGR
+     * @param matType  转换成mat的type 如 CvType.CV_8UC3
+     *                 https://wenku.baidu.com/view/3cd5e54b5bfafab069dc5022aaea998fcc2240a1.html
+     */
+    public static Mat bufImg2Mat(BufferedImage original, int imgType, int matType) {
+        if (original == null) {
+            throw new IllegalArgumentException("original == null");
+        }
+        // Don't convert if it already has correct type
+        if (original.getType() != imgType) {
+            // Create a buffered image
+            BufferedImage image = new BufferedImage(original.getWidth(), original.getHeight(), imgType);
+            // Draw the image onto the new buffer
+            Graphics2D g = image.createGraphics();
+            try {
+                g.setComposite(AlphaComposite.Src);
+                g.drawImage(original, 0, 0, null);
+                original = image;
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                g.dispose();
+            }
+        }
+        byte[] pixels = ((DataBufferByte) original.getRaster().getDataBuffer()).getData();
+        Mat mat = Mat.eye(original.getHeight(), original.getWidth(), matType);
+        mat.put(0, 0, pixels);
+        return mat;
+    }
+
+}
+

+ 69 - 0
src/main/java/com/test/xiaoshi/test/common/util/OpenCVUtil.java

@@ -0,0 +1,69 @@
+package com.test.xiaoshi.test.common.util;
+
+import org.opencv.core.Core;
+import org.opencv.core.Mat;
+import org.opencv.core.Size;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import static org.opencv.imgproc.Imgproc.*;
+
+@Component
+@Scope(value = "singleton")
+public class OpenCVUtil {
+
+	/**
+     * 日志组件可根据自己项目更换
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenCVUtil.class);
+
+	/**
+     * 1.什么是java.awt.headless模式
+     * java.awt.headless是J2SE的一种模式,用于在缺失显示屏、鼠标或者键盘时的系统配置。对于后端服务来讲,很多都是需要将这个属性设置为true的。
+     * 2.什么时候使用java.awt.headless模式
+     * 对于开发者来讲常常需要在该模式下工作。因为服务器(如提供Web服务的)往往可能缺少前述设备,但又需要使用他们提供的功能,生成相应的数据,以提供给客户端(如浏览器所在的配有相关的、键盘和的主机)。
+     */
+    static {
+        try {
+            // 解决awt报错问题
+            logger.info("启动headless mode...");
+            System.setProperty("java.awt.headless", "true");
+            logger.info("动态库路径:{}", System.getProperty("java.library.path"));
+            logger.info("开始加载OpenCV库...");
+            System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
+            logger.info("load success");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 图片清晰度增强
+     * 使用高斯滤波器,高斯滤镜可减少图像中的噪声并使它看起来更好(或更高分辨率)
+     * http://www.srcmini.com/70014.html
+     *
+     * @param base64 图片Base64
+     */
+
+
+    /**
+     * 图片对比度增强
+     * 使用直方图均衡
+     * http://www.srcmini.com/70010.html
+     *
+     * @param base64 图片Base64
+     */
+
+    /**
+     * 图片无损放大
+     * 使用高斯金字塔
+     * https://blog.csdn.net/datouniao1/article/details/108535563
+     *
+     * @param base64 图片Base64(去文件头)
+     */
+
+
+}
+

+ 22 - 0
src/main/java/com/test/xiaoshi/test/controller/OpencvController.java

@@ -0,0 +1,22 @@
+package com.test.xiaoshi.test.controller;
+
+
+import com.test.xiaoshi.test.service.ImageFeatureService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping( "client")
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class OpencvController {
+    private final ImageFeatureService imageFeatureService;
+    @PostMapping("/add")
+    public String addClient() {
+        imageFeatureService.getImage();
+return "";
+    }
+}

+ 61 - 0
src/main/java/com/test/xiaoshi/test/service/ImageFeatureService.java

@@ -0,0 +1,61 @@
+package com.test.xiaoshi.test.service;
+
+import org.opencv.core.*;
+import org.opencv.features2d.DescriptorExtractor;
+import org.opencv.features2d.FeatureDetector;
+import org.opencv.features2d.Features2d;
+import org.opencv.imgproc.Imgproc;
+import org.springframework.stereotype.Service;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.io.File;
+import java.io.FileInputStream;
+
+@Service
+public class ImageFeatureService {
+
+    public float[] extractFeatures(BufferedImage image) {
+
+        // 将BufferedImage转换为OpenCV的Mat对象  
+        Mat matImage = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3);
+        byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
+        matImage.put(0, 0, data);
+System.out.println(matImage.type());
+        // 转换为灰度图像(如果需要)  
+        Mat grayImage = new Mat();
+        Imgproc.cvtColor(matImage, grayImage, Imgproc.COLOR_BGR2GRAY);
+        // 初始化特征检测器和描述子提取器  
+        FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
+        DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
+
+        // 检测特征点  
+        MatOfKeyPoint keyPoints = new MatOfKeyPoint();
+        detector.detect(grayImage, keyPoints);
+
+        // 提取特征描述子  
+        Mat descriptors = new Mat();
+        extractor.compute(grayImage, keyPoints, descriptors);
+        matImage.convertTo(descriptors, CvType.CV_32F);
+        System.out.println(descriptors.type());
+        // 将描述子转换为float数组  
+        float[] featureVector = new float[descriptors.cols() * descriptors.rows()];
+        descriptors.get(0, 0, featureVector);
+        return featureVector;
+    }
+
+    public void getImage() {
+        File file = new File("D:\\xiaoshi-test\\target\\zxy.jpg");
+        try {
+            FileInputStream fileInputStream = new FileInputStream(file);
+            BufferedImage image = ImageIO.read(fileInputStream);
+            float[] featureVector = this.extractFeatures(image);
+            System.out.println(featureVector);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
+}

+ 30 - 0
src/main/resources/application-dev.yml

@@ -0,0 +1,30 @@
+spring:
+  #    # 使用 smtp 协议
+  #  mail.protocol: smtps
+  #  mail.host: smtp.exmail.qq.com
+  #  mail.port: 465
+  #  mail.username: shenyongyi@china-wispro.com
+  #    # 授权码
+  #  mail.password: c3hY5cgAexhhr9HL
+  #  mail.test-connection: false
+  #  mail.properties.mail.smtp.auth: true
+  #  mail.properties.mail.debug: false
+  #  mail.properties.mail.mime.splitlongparameters: false
+  #  mail.default-encoding: UTF-8
+  # rabbitmq
+  rabbitmq.host: 192.168.1.24
+  rabbitmq.port: 5672
+  rabbitmq.username: admin
+  rabbitmq.password: 123456
+  redis:
+    host: 192.168.1.24
+    port: 6379
+    database: 3
+    password: Xx0GWxdWQJxx6Swe
+    lettuce:
+      pool:
+        max-active: 20
+        max-idle: 20
+        min-idle: 0
+        max-wait: -1ms
+    timeout: 2000ms

+ 0 - 1
src/main/resources/application.properties

@@ -1 +0,0 @@
-

+ 47 - 0
src/main/resources/application.yml

@@ -0,0 +1,47 @@
+server:
+  servlet:
+    context-path: /
+  port: 8871
+sa-token:
+  activity-timeout: 18000
+  token-name: token
+  token-style: tik
+  #  是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
+  is-concurrent: true
+  timeout: 604800
+spring:
+  thymeleaf:
+    cache: false
+    mode: HTML5
+  aop:
+    auto: true
+    proxy-target-class: true
+  application:
+    name: pcs
+  servlet:
+    multipart:
+      max-file-size: 1000MB
+      max-request-size: 1000MB
+  profiles:
+    active: dev
+  jackson:
+    default-property-inclusion: non_null
+    serialization:
+      INDENT_OUTPUT: true
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: Asia/Shanghai
+#mybatis
+mybatis-plus:
+  typeAliasesPackage: cn.cslg.permission.entity
+  global-config:
+    db-config:
+      id-type: AUTO
+      logic-delete-value: 0
+      logic-not-delete-value: 1
+  configuration:
+    #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+  mapper-locations: classpath:mapper/*.xml
+
+

BIN
src/main/resources/lib.opencv/opencv-480.jar