车车 7 ヶ月 前
コミット
1a3e18a217

+ 4 - 3
ktg-common/src/main/java/com/ktg/common/utils/face/FaceMatchUtil.java

@@ -51,11 +51,11 @@ public class FaceMatchUtil
     /**
      * 人脸识别对比
      */
-    public static FaceMatchVO faceRecognitionComparison(MultipartFile mfile, Set<String> image2) throws IOException {
+    public static FaceMatchVO faceRecognitionComparison(MultipartFile mfile, List<String> image2) throws IOException {
         Mat mat1 = conv_mat(mfile); // 转换为灰度图像的Mat对象
         Mat hist1 = computeHistogram(mat1); // 计算第一个图像的直方图
 
-        ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); // 创建线程池
+        ExecutorService executorService = Executors.newFixedThreadPool(4); // 创建线程池
         List<Future<FaceMatchVO>> futures = new ArrayList<>(); // 存储Future对象的列表
 
         for (String imgPath : image2) { // 遍历第二个图像集合
@@ -75,6 +75,7 @@ public class FaceMatchUtil
         }
 
         try {
+            
             for (Future<FaceMatchVO> future : futures) { // 遍历所有Future对象
                 FaceMatchVO result = future.get(); // 获取执行结果
                 if (result != null) { // 如果结果不为空,说明找到了匹配的图像
@@ -127,7 +128,7 @@ public class FaceMatchUtil
     private static Mat computeHistogram(Mat mat) {
         Mat hist = new Mat(); // 创建用于存储直方图的Mat对象
         MatOfFloat ranges = new MatOfFloat(0f, 256f); // 定义直方图的范围
-        MatOfInt histSize = new MatOfInt(1000); // 定义直方图的大小(越大越精确,但计算速度越慢)
+        MatOfInt histSize = new MatOfInt(100); // 定义直方图的大小(越大越精确,但计算速度越慢)
         Imgproc.calcHist(Collections.singletonList(mat), new MatOfInt(0), new Mat(), hist, histSize, ranges); // 计算直方图
         Core.normalize(hist, hist, 0, 1, Core.NORM_MINMAX); // 归一化直方图,使其值在0到1之间
         return hist; // 返回计算好的直方图

+ 2 - 1
ktg-framework/src/main/java/com/ktg/framework/web/service/SysLoginService.java

@@ -259,7 +259,8 @@ public class SysLoginService {
         // 通过人脸获取最相似的用户
         // 记录开始时间
         long startTime1 = System.currentTimeMillis();
-        FaceMatchVO faceMatchVO = FaceMatchUtil.faceRecognitionComparison(file, new HashSet<>(collect));
+        // FaceMatchVO faceMatchVO = FaceMatchUtil.faceRecognitionComparison(file, new HashSet<>(collect));
+        FaceMatchVO faceMatchVO = FaceMatchUtil.faceRecognitionComparison(file, collect);
         // 记录结束时间
         long endTime1 = System.currentTimeMillis();
         // 计算时间差(毫秒)