1、人脸模块:人脸查询支持 向量数据库Milvus 和 SQLite

2、人脸模块:FaceNet人脸模型也支持人脸注册,查询等功能
3、人脸模块:Seetaface6 自动下载人脸库
4、人脸模块:Seetaface6解决依赖库重复下载问题
5、人脸模块:支持手动加载人脸库
6、人脸模块:人脸识别相关功能支持更多参数
This commit is contained in:
dengwenjie
2025-06-09 12:12:10 +08:00
parent ad6706f559
commit bca9462331
67 changed files with 4170 additions and 1438 deletions

View File

@@ -79,7 +79,7 @@ public class FaceUtils {
* @param seetaResult
* @return
*/
public static DetectionResponse convertToDetectionResponse(SeetaRect[] seetaResult, FaceModelConfig config,List<SeetaPointF[]> seetaPointFSList){
public static DetectionResponse convertToDetectionResponse(SeetaRect[] seetaResult, List<SeetaPointF[]> seetaPointFSList){
if(Objects.isNull(seetaResult) || seetaResult.length == 0){
return null;
}
@@ -104,6 +104,57 @@ public class FaceUtils {
return detectionResponse;
}
/**
* 转换为FaceDetectedResult(人脸特征提取)
* @param seetaResult
* @return
*/
public static DetectionResponse featuresConvertToResponse(SeetaRect[] seetaResult, List<SeetaPointF[]> seetaPointFSList, List<float[]> featureList){
if(Objects.isNull(seetaResult) || seetaResult.length == 0){
return null;
}
List<DetectionInfo> detectionInfoList = new ArrayList<DetectionInfo>();
for(int i = 0; i < seetaResult.length; i++){
SeetaRect rect = seetaResult[i];
DetectionRectangle rectangle = new DetectionRectangle(rect.x, rect.y, rect.width, rect.height);
FaceInfo faceInfo = new FaceInfo();
if(seetaPointFSList != null && seetaPointFSList.size() > 0){
SeetaPointF[] seetaPointFS = seetaPointFSList.get(i);
List<Point> keyPoints = Arrays.stream(seetaPointFS)
.map(p -> new Point(p.x, p.y))
.collect(Collectors.toList());
faceInfo.setKeyPoints(keyPoints);
}
if(featureList != null && featureList.size() > 0){
faceInfo.setFeature(featureList.get(i));
}
detectionInfoList.add(new DetectionInfo(rectangle, 0, faceInfo));
}
return new DetectionResponse(detectionInfoList);
}
/**
* 转换为FaceDetectedResult(人脸特征提取)
* @param rect
* @param seetaPointFS
* @param feature
* @return
*/
public static DetectionResponse featuresConvertToResponse(SeetaRect rect, SeetaPointF[] seetaPointFS, float[] feature){
List<DetectionInfo> detectionInfoList = new ArrayList<DetectionInfo>();
DetectionRectangle rectangle = new DetectionRectangle(rect.x, rect.y, rect.width, rect.height);
FaceInfo faceInfo = new FaceInfo();
List<Point> keyPoints = Arrays.stream(seetaPointFS)
.map(p -> new Point(p.x, p.y))
.collect(Collectors.toList());
faceInfo.setKeyPoints(keyPoints);
faceInfo.setFeature(feature);
detectionInfoList.add(new DetectionInfo(rectangle, 0, faceInfo));
return new DetectionResponse(detectionInfoList);
}
/**
* 绘制人脸框
* @param sourceImage
@@ -572,6 +623,28 @@ public class FaceUtils {
}
}
/**
* 将 Milvus 查询返回的得分转换为 0~1 范围的相似度
* @param metricType 向量度量方式IP 或 L2
* @param score 原始得分L2 为距离IP 为相似度)
* @return 映射后的相似度0~1
*/
public static float convertScoreToSimilarity(String metricType, float score) {
switch (metricType.toUpperCase()) {
case "IP":
// 内积 IP 的范围为 [-1, 1],归一化为 [0, 1]
return (score + 1.0f) / 2.0f;
case "L2":
// 欧氏距离 L2距离越小越相似1 / (1 + 距离) 映射到 (0, 1]
return 1.0f / (1.0f + score);
case "COSINE":
// 余弦相似度 COSINE本身范围为 [-1, 1],也需要归一化到 [0, 1]
return (score + 1.0f) / 2.0f;
default:
throw new IllegalArgumentException("Unsupported metricType: " + metricType);
}
}
}