|
|
@@ -18,14 +18,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
@@ -106,8 +102,6 @@ public class ArcSoftMothodUtil {
|
|
|
if (StringUtils.isBlank(prodApi)) {
|
|
|
basePath = "C:" + basePath;
|
|
|
}
|
|
|
- // 人脸特征值存储
|
|
|
- String content;
|
|
|
// 原文件转存后的路径
|
|
|
String imagePath;
|
|
|
// 原文件转存后的前端请求路径
|
|
|
@@ -155,39 +149,12 @@ public class ArcSoftMothodUtil {
|
|
|
return faceCutVO;
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) throws UnsupportedEncodingException {
|
|
|
-
|
|
|
-
|
|
|
- /*String strWithCharset = new String(bytes, StandardCharsets.UTF_8); // 使用默认字符集
|
|
|
- System.out.println(bytes);
|
|
|
- System.out.println(strWithCharset);
|
|
|
- byte[] bytes1 = strWithCharset.getBytes(StandardCharsets.UTF_8);
|
|
|
- for (byte b : bytes1) {
|
|
|
- System.out.print(b + " ");
|
|
|
- }*/
|
|
|
- byte[] bytes = {72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33};
|
|
|
- String string = Arrays.toString(bytes);
|
|
|
-
|
|
|
- // Remove the brackets and spaces from the string
|
|
|
- string = string.substring(1, string.length() - 1).replaceAll("\\s", "");
|
|
|
-
|
|
|
- // Split the string by commas to get each number as a string
|
|
|
- String[] numbers = string.split(",");
|
|
|
- // Create a new byte array with the same length as the original
|
|
|
- byte[] newBytes = new byte[numbers.length];
|
|
|
-
|
|
|
- // Convert each string number back to a byte and store it in the new array
|
|
|
- for (int i = 0; i < numbers.length; i++) {
|
|
|
- newBytes[i] = Byte.parseByte(numbers[i]);
|
|
|
- }
|
|
|
- // Print the new byte array to verify it matches the original
|
|
|
- }
|
|
|
|
|
|
// 相似度门槛
|
|
|
private static final double THRESHOLD = 0.8; // THRESHOLD越高,错误率越低,阈值[0,1]
|
|
|
private static final ExecutorService THREAD_POOL_EXECUTOR = Executors.newFixedThreadPool(4); // 线程池
|
|
|
|
|
|
- public static FaceMatchVO completableFutureComparison(final MultipartFile file, final List<String> matcher) throws IOException {
|
|
|
+ public static FaceMatchVO completableFutureComparison(final MultipartFile file, final Set<String> matcher) throws IOException {
|
|
|
int errorCode;
|
|
|
// 提取当前人脸的特征值,比对文件零时存储,人脸存储基础路径
|
|
|
String profile = RuoYiConfig.getProfile();
|
|
|
@@ -249,10 +216,7 @@ public class ArcSoftMothodUtil {
|
|
|
List<List<String>> averageMatcherFeatureDataList = Lists.partition(matcherFeatureDataList, matcherFeatureDataList.size() / denominator);
|
|
|
|
|
|
// 构建四个线程进行处理,防止人员过多对比速度太慢
|
|
|
- CompletableFuture<FaceMatchVO>[] completableFutureArray = averageMatcherFeatureDataList.stream().map(
|
|
|
- partitionFeatureData -> CompletableFuture.supplyAsync(
|
|
|
- () -> comparison(featureData, new ArrayList<>(partitionFeatureData)), THREAD_POOL_EXECUTOR)
|
|
|
- ).toArray(CompletableFuture[]::new);
|
|
|
+ CompletableFuture<FaceMatchVO>[] completableFutureArray = averageMatcherFeatureDataList.stream().map(partitionFeatureData -> CompletableFuture.supplyAsync(() -> comparison(featureData, new ArrayList<>(partitionFeatureData)), THREAD_POOL_EXECUTOR)).toArray(CompletableFuture[]::new);
|
|
|
// 等待所有任务执行完
|
|
|
CompletableFuture.allOf(completableFutureArray).join();
|
|
|
List<FaceMatchVO> verificationList = new ArrayList<>();
|
|
|
@@ -274,6 +238,9 @@ public class ArcSoftMothodUtil {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("人脸比对异常:{}", e.getMessage());
|
|
|
+ } finally {
|
|
|
+ //特征值提取完毕后清除数据
|
|
|
+ removeFile(fileName);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -327,4 +294,15 @@ public class ArcSoftMothodUtil {
|
|
|
return newBytes;
|
|
|
}
|
|
|
|
|
|
+ private static void removeFile(String path) {
|
|
|
+ try {
|
|
|
+ File file = new File(path);
|
|
|
+ if (!file.delete()) {
|
|
|
+ log.error("DAT文件删除失败: " + path);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("存在异常文件:{}", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|