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