mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-20 01:29:18 +00:00
【人脸识别】 新增多种人脸识别模型
【底层优化】 支持自由选择 OpenCV 或 BufferedImage 作为图像引擎 【通用图像】 全部模型启用 Image 输入,支持各类图片格式与 Image 的互转 【模型管理】 优化模型生命周期,关闭后可重新创建 【人脸识别】 支持在人脸查询结果中绘制姓名标注 【人脸检测】 新增人脸裁剪功能 【修复】 修复若干已知问题,提升系统稳定性
This commit is contained in:
@@ -18,6 +18,7 @@ import cn.smartjavaai.common.utils.Base64ImageUtils;
|
||||
import cn.smartjavaai.common.utils.ImageUtils;
|
||||
import cn.smartjavaai.instanceseg.exception.InstanceSegException;
|
||||
import cn.smartjavaai.objectdetection.exception.DetectionException;
|
||||
import cn.smartjavaai.pose.model.PoseDetModelFactory;
|
||||
import cn.smartjavaai.semseg.config.SemSegModelConfig;
|
||||
import cn.smartjavaai.semseg.criteria.SemSegCriteriaFactory;
|
||||
import cn.smartjavaai.vision.utils.CategoryMaskFilter;
|
||||
@@ -122,6 +123,7 @@ public class CommonSemSegModel implements SemSegModel {
|
||||
}
|
||||
ImageUtils.drawMask(categoryMask, img, 180, 0);
|
||||
img.save(Files.newOutputStream(Paths.get(outputPath)), "png");
|
||||
ImageUtils.releaseOpenCVMat(img);
|
||||
return R.ok(categoryMask);
|
||||
} catch (IOException e) {
|
||||
throw new InstanceSegException(e);
|
||||
@@ -141,6 +143,9 @@ public class CommonSemSegModel implements SemSegModel {
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if (fromFactory) {
|
||||
SemSegModelFactory.removeFromCache(config.getModelEnum());
|
||||
}
|
||||
try {
|
||||
if (predictorPool != null) {
|
||||
predictorPool.close();
|
||||
@@ -156,4 +161,14 @@ public class CommonSemSegModel implements SemSegModel {
|
||||
log.warn("关闭 model 失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fromFactory = false;
|
||||
|
||||
@Override
|
||||
public void setFromFactory(boolean fromFactory) {
|
||||
this.fromFactory = fromFactory;
|
||||
}
|
||||
public boolean isFromFactory() {
|
||||
return fromFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,5 +38,8 @@ public interface SemSegModel extends AutoCloseable{
|
||||
}
|
||||
|
||||
|
||||
default void setFromFactory(boolean fromFactory){
|
||||
throw new UnsupportedOperationException("默认不支持该功能");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ public class SemSegModelFactory {
|
||||
throw new DetectionException(e);
|
||||
}
|
||||
model.loadModel(config);
|
||||
model.setFromFactory(true);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -97,6 +98,19 @@ public class SemSegModelFactory {
|
||||
modelMap.remove(modelEnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭所有已加载的模型
|
||||
*/
|
||||
public void closeAll() {
|
||||
modelMap.values().forEach(model -> {
|
||||
try {
|
||||
model.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
modelMap.clear();
|
||||
}
|
||||
|
||||
// 初始化默认算法
|
||||
static {
|
||||
|
||||
Reference in New Issue
Block a user