From a8e7ce6c4edacc967937373fd3933992e4d14f19 Mon Sep 17 00:00:00 2001
From: dengwenjie <775747758@qq.com>
Date: Sun, 7 Sep 2025 17:19:19 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E3=80=90=E4=BA=BA=E8=84=B8=E6=A3=80?=
=?UTF-8?q?=E6=B5=8B=E3=80=91=E6=96=B0=E5=A2=9E6=E4=B8=AA=E6=A8=A1?=
=?UTF-8?q?=E5=9E=8B(MTCNN=E3=80=81YOLOV5=E3=80=81RetinaFace=E5=B0=8F?=
=?UTF-8?q?=E5=B0=BA=E5=AF=B8=E7=89=88)=EF=BC=8C=E5=A4=A7=E5=B9=85?=
=?UTF-8?q?=E6=8F=90=E5=8D=87=E6=80=A7=E8=83=BD=20-=20=E3=80=90=E4=BA=BA?=
=?UTF-8?q?=E8=84=B8=E8=AF=86=E5=88=AB=E3=80=91=E6=96=B0=E5=A2=9ESeetaface?=
=?UTF-8?q?6=E8=BD=BB=E9=87=8F=E6=A8=A1=E5=9E=8B=20-=20=E3=80=90=E7=9B=AE?=
=?UTF-8?q?=E6=A0=87=E6=A3=80=E6=B5=8B=E3=80=91=E6=94=AF=E6=8C=81=E8=A7=86?=
=?UTF-8?q?=E9=A2=91=E6=B5=81=E7=9B=AE=E6=A0=87=E6=A3=80=E6=B5=8B=EF=BC=88?=
=?UTF-8?q?rtsp=E3=80=81=E8=A7=86=E9=A2=91=E6=96=87=E4=BB=B6=E7=AD=89?=
=?UTF-8?q?=EF=BC=89=20-=20=E3=80=90=E7=9B=AE=E6=A0=87=E6=A3=80=E6=B5=8B?=
=?UTF-8?q?=E3=80=91=E6=94=AF=E6=8C=81tensorflow2=E7=9B=AE=E6=A0=87?=
=?UTF-8?q?=E6=A3=80=E6=B5=8B=E6=A8=A1=E5=9E=8B=20-=20=E3=80=90=E7=9B=AE?=
=?UTF-8?q?=E6=A0=87=E6=A3=80=E6=B5=8B=E3=80=91=E6=96=B0=E5=A2=9E=E8=A1=8C?=
=?UTF-8?q?=E4=BA=BA=E6=A3=80=E6=B5=8B=E6=A8=A1=E5=9E=8B(yolo-person)=20-?=
=?UTF-8?q?=20=E3=80=90=E9=80=9A=E7=94=A8=E8=A7=86=E8=A7=89=E3=80=91?=
=?UTF-8?q?=E6=96=B0=E5=A2=9E4=E4=B8=AA=E5=8A=A8=E4=BD=9C=E8=AF=86?=
=?UTF-8?q?=E5=88=AB=E6=A8=A1=E5=9E=8B=20-=20=E3=80=90=E9=80=9A=E7=94=A8?=
=?UTF-8?q?=E8=A7=86=E8=A7=89=E3=80=91=E6=96=B0=E5=A2=9E=E8=AF=AD=E4=B9=89?=
=?UTF-8?q?=E5=88=86=E5=89=B2=E6=A8=A1=E5=9E=8B=20-=20=E3=80=90=E9=80=9A?=
=?UTF-8?q?=E7=94=A8=E8=A7=86=E8=A7=89=E3=80=91=E6=96=B0=E5=A2=9E5?=
=?UTF-8?q?=E4=B8=AA=E5=AE=9E=E4=BE=8B=E5=88=86=E5=89=B2=E6=A8=A1=E5=9E=8B?=
=?UTF-8?q?(=E5=90=AByolov8-seg=E3=80=81yolov11-seg)=20-=20=E3=80=90?=
=?UTF-8?q?=E9=80=9A=E7=94=A8=E8=A7=86=E8=A7=89=E3=80=91=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?yolo-obb11=E6=97=8B=E8=BD=AC=E6=A1=86=E6=A3=80=E6=B5=8B(?=
=?UTF-8?q?=E5=90=AByolov11-obb)=20-=20=E3=80=90=E9=80=9A=E7=94=A8?=
=?UTF-8?q?=E8=A7=86=E8=A7=89=E3=80=91=E6=96=B0=E5=A2=9E5=E4=B8=AA?=
=?UTF-8?q?=E5=A7=BF=E6=80=81=E4=BC=B0=E8=AE=A1=E6=A8=A1=E5=9E=8B(?=
=?UTF-8?q?=E5=90=AByolov8-pose=E3=80=81yolov11-pose)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 341 +++++++----
.../common/entity/DetectionResponse.java | 3 +-
.../smartjavaai/common/entity/ObbDetInfo.java | 3 +
.../common/utils/FrameConverterUtil.java | 66 ---
.../smartjavaai/common/utils/ImageUtils.java | 84 +++
.../smartjavaai/common/utils/OpenCVUtils.java | 46 +-
.../smartjavaai/common/utils/VideoUtils.java | 77 ---
examples/face-example/pom.xml | 58 +-
.../examples/face/PythonTranslator.java | 118 ----
.../main/java/smartai/examples/face/Test.java | 99 ----
.../java/smartai/examples/face/VideoDemo.java | 25 -
.../face/attribute/FaceAttributeDetDemo.java | 18 +-
.../face/expression/ExpressionRecDemo.java | 2 +
.../examples/face/facedet/FaceDetDemo.java | 3 +-
.../examples/face/facerec/FaceRecDemo.java | 10 +-
.../face/liveness/LivenessDetDemo.java | 2 +-
.../face/quality/FaceQualityDetDemo.java | 1 +
examples/objectdetection-example/.gitignore | 7 -
.../output/object_detection_detected.png | Bin 1863518 -> 0 bytes
.../objectdetection/ObjectDetection.java | 343 -----------
.../src/main/resources/META-INF/MANIFEST.MF | 3 -
.../ocr-examples/output/plate_recognized2.jpg | Bin 87787 -> 1482938 bytes
examples/ocr-examples/pom.xml | 39 +-
.../examples/ocr/common/OcrDetectionDemo.java | 3 +-
.../ocr/common/OcrDirectionDetDemo.java | 6 +-
.../examples/ocr/common/OcrRecognizeDemo.java | 10 +-
.../examples/ocr/plate/PlateRecDemo.java | 46 +-
.../examples/ocr/table/TableRecDemo.java | 10 +-
examples/speech-examples/pom.xml | 15 +-
.../speech/asr/SpeechRecognizeDemo.java | 10 +-
examples/translation-example/pom.xml | 63 ++-
.../nlp/translation/TranslationDemo.java | 105 +++-
.../README.md | 0
.../pom.xml | 119 ++--
.../examples/vision/ActionRecognizeDemo.java | 92 +++
.../examples/vision/InstanceSegDemo.java | 135 +++++
.../smartai/examples/vision/ObbDetDemo.java | 129 +++++
.../examples/vision/ObjectDetectionDemo.java | 420 ++++++++++++++
.../examples/vision/PersonDetectDemo.java | 121 ++++
.../smartai/examples/vision/PoseDetDemo.java | 118 ++++
.../smartai/examples/vision/SemSegDemo.java | 123 ++++
.../smartai/examples/vision}/ViewerFrame.java | 2 +-
.../src/main/resources/META-INF/MANIFEST.MF | 3 +
.../src/main/resources/action/calling.jpeg | Bin 0 -> 70531 bytes
.../src/main/resources/action/dance.jpg | Bin 0 -> 18935 bytes
.../src/main/resources/dog_bike_car.jpg | Bin
.../src/main/resources/largest_selfie.jpg | Bin
.../src/main/resources/logback.xml | 0
.../src/main/resources/obb/boats.jpg | Bin 0 -> 194872 bytes
.../src/main/resources/object_detection.jpg | Bin
.../src/main/resources/person/person.png | Bin 0 -> 450765 bytes
.../src/main/resources/pose/pose_soccer.png | Bin 0 -> 1598682 bytes
.../src/main/resources/segmentation.jpg | Bin 0 -> 91548 bytes
.../src/main/resources/zero/000000039769.jpg | Bin 0 -> 173131 bytes
.../model/facedect/MtcnnFaceDetModel.java | 15 +-
.../liveness/MiniVisionLivenessModel.java | 3 -
.../Yolo5PlateDetectTranslator.java | 6 +-
pom.xml | 22 +-
vision/pom.xml | 25 +-
.../criteria/ActionRecCriteriaFactory.java | 65 ++-
.../action/enums/ActionRecModelEnum.java | 51 +-
.../action/model/ActionRecModel.java | 9 -
.../action/model/ActionRecModelFactory.java | 111 ++++
.../action/model/CommonActionRecModel.java | 16 +-
.../action/model/CommonActionTranslator.java | 1 -
.../config/InstanceSegModelConfig.java | 2 +-
.../criteria/InstanceSegCriteriaFactory.java | 49 +-
.../enums/InstanceSegModelEnum.java | 41 +-
.../model/CommonInstanceSegModel.java | 6 +
.../model/InstanceSegModelFactory.java | 111 ++++
.../obb/config/ObbDetModelConfig.java | 59 ++
.../obb/criteria/ObbDetCriteriaFactory.java | 70 +++
.../cn/smartjavaai/obb/entity/ObbResult.java | 20 +
.../obb/entity/YoloRotatedBox.java | 98 ++++
.../obb/enums/ObbDetModelEnum.java | 59 ++
.../obb/exception/ObbDetException.java | 29 +
.../obb/model/CommonObbDetModel.java | 160 ++++++
.../cn/smartjavaai/obb/model/ObbDetModel.java | 60 ++
.../obb/model/ObbDetModelFactory.java | 107 ++++
.../obb/translator/YoloV11OddTranslator.java | 532 ++++++++++++++++++
.../config/PersonDetModelConfig.java | 6 -
.../criteria/CriteriaBuilderFactory.java | 16 +-
.../enums/DetectorModelEnum.java | 49 +-
.../objectdetection/model/DetectorModel.java | 9 +-
.../model/ObjectDetectionModelFactory.java | 12 +-
.../model/person/CommonPersonDetModel.java | 18 +-
.../model/person/PersonDetModelFactory.java | 109 ++++
.../stream/StreamDetectionListener.java | 16 +
.../stream/StreamDetector.java | 226 ++++++--
.../translator/YoloV8PersonDetTranslator.java | 13 +-
.../pose/config/PoseModelConfig.java | 52 ++
.../pose/criteria/PoseCriteriaFactory.java | 78 +++
.../smartjavaai/pose/enums/PoseModelEnum.java | 42 ++
.../pose/exception/PoseException.java | 29 +
.../pose/model/CommonPoseModel.java | 147 +++++
.../pose/model/PoseDetModelFactory.java | 112 ++++
.../cn/smartjavaai/pose/model/PoseModel.java | 53 ++
.../semseg/model/CommonSemSegModel.java | 52 +-
.../smartjavaai/semseg/model/SemSegModel.java | 18 +-
.../semseg/model/SemSegModelFactory.java | 107 ++++
.../vision/utils/DetectorUtils.java | 60 +-
.../vision/utils/ObbResultFilter.java | 12 +-
102 files changed, 4473 insertions(+), 1368 deletions(-)
delete mode 100644 common/src/main/java/cn/smartjavaai/common/utils/FrameConverterUtil.java
delete mode 100644 common/src/main/java/cn/smartjavaai/common/utils/VideoUtils.java
delete mode 100644 examples/face-example/src/main/java/smartai/examples/face/PythonTranslator.java
delete mode 100644 examples/face-example/src/main/java/smartai/examples/face/Test.java
delete mode 100644 examples/face-example/src/main/java/smartai/examples/face/VideoDemo.java
delete mode 100644 examples/objectdetection-example/.gitignore
delete mode 100644 examples/objectdetection-example/output/object_detection_detected.png
delete mode 100644 examples/objectdetection-example/src/main/java/smartai/examples/objectdetection/ObjectDetection.java
delete mode 100644 examples/objectdetection-example/src/main/resources/META-INF/MANIFEST.MF
rename examples/{objectdetection-example => vision-example}/README.md (100%)
rename examples/{objectdetection-example => vision-example}/pom.xml (78%)
create mode 100644 examples/vision-example/src/main/java/smartai/examples/vision/ActionRecognizeDemo.java
create mode 100644 examples/vision-example/src/main/java/smartai/examples/vision/InstanceSegDemo.java
create mode 100644 examples/vision-example/src/main/java/smartai/examples/vision/ObbDetDemo.java
create mode 100644 examples/vision-example/src/main/java/smartai/examples/vision/ObjectDetectionDemo.java
create mode 100644 examples/vision-example/src/main/java/smartai/examples/vision/PersonDetectDemo.java
create mode 100644 examples/vision-example/src/main/java/smartai/examples/vision/PoseDetDemo.java
create mode 100644 examples/vision-example/src/main/java/smartai/examples/vision/SemSegDemo.java
rename examples/{objectdetection-example/src/main/java/smartai/examples/objectdetection => vision-example/src/main/java/smartai/examples/vision}/ViewerFrame.java (98%)
create mode 100644 examples/vision-example/src/main/resources/META-INF/MANIFEST.MF
create mode 100644 examples/vision-example/src/main/resources/action/calling.jpeg
create mode 100644 examples/vision-example/src/main/resources/action/dance.jpg
rename examples/{objectdetection-example => vision-example}/src/main/resources/dog_bike_car.jpg (100%)
rename examples/{objectdetection-example => vision-example}/src/main/resources/largest_selfie.jpg (100%)
rename examples/{objectdetection-example => vision-example}/src/main/resources/logback.xml (100%)
create mode 100644 examples/vision-example/src/main/resources/obb/boats.jpg
rename examples/{objectdetection-example => vision-example}/src/main/resources/object_detection.jpg (100%)
create mode 100644 examples/vision-example/src/main/resources/person/person.png
create mode 100644 examples/vision-example/src/main/resources/pose/pose_soccer.png
create mode 100644 examples/vision-example/src/main/resources/segmentation.jpg
create mode 100644 examples/vision-example/src/main/resources/zero/000000039769.jpg
create mode 100644 vision/src/main/java/cn/smartjavaai/action/model/ActionRecModelFactory.java
create mode 100644 vision/src/main/java/cn/smartjavaai/instanceseg/model/InstanceSegModelFactory.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/config/ObbDetModelConfig.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/criteria/ObbDetCriteriaFactory.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/entity/ObbResult.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/entity/YoloRotatedBox.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/enums/ObbDetModelEnum.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/exception/ObbDetException.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/model/CommonObbDetModel.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/model/ObbDetModel.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/model/ObbDetModelFactory.java
create mode 100644 vision/src/main/java/cn/smartjavaai/obb/translator/YoloV11OddTranslator.java
create mode 100644 vision/src/main/java/cn/smartjavaai/objectdetection/model/person/PersonDetModelFactory.java
create mode 100644 vision/src/main/java/cn/smartjavaai/pose/config/PoseModelConfig.java
create mode 100644 vision/src/main/java/cn/smartjavaai/pose/criteria/PoseCriteriaFactory.java
create mode 100644 vision/src/main/java/cn/smartjavaai/pose/enums/PoseModelEnum.java
create mode 100644 vision/src/main/java/cn/smartjavaai/pose/exception/PoseException.java
create mode 100644 vision/src/main/java/cn/smartjavaai/pose/model/CommonPoseModel.java
create mode 100644 vision/src/main/java/cn/smartjavaai/pose/model/PoseDetModelFactory.java
create mode 100644 vision/src/main/java/cn/smartjavaai/pose/model/PoseModel.java
create mode 100644 vision/src/main/java/cn/smartjavaai/semseg/model/SemSegModelFactory.java
diff --git a/README.md b/README.md
index 5d11bca..a5123c1 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
- 人脸比对1:N
+ 人脸比对1:N (Face Recognition)
- 人脸对齐
- 人脸注册
- 人脸库查询
@@ -101,11 +101,11 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
人脸属性检测
- - 性别检测
- - 年龄检测
- - 口罩检测
- - 眼睛状态检测
- - 脸部姿态检测
+ - 性别检测(GenderDetection)
+ - 年龄检测(AgeDetection)
+ - 口罩检测(Face Mask Detection)
+ - 眼睛状态检测(EyeClosenessDetection)
+ - 脸部姿态检测(FacePoseEstimation)
|
@@ -117,7 +117,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
|
- 活体检测
+ 活体检测 (FaceLivenessDetection)
- 图片和视频活体检测
|
@@ -130,7 +130,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
- 人脸表情识别
+ 人脸表情识别 (FacialExpressionRecognition)
- 7种表情检测
|
@@ -143,7 +143,8 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
- 目标检测
+ 目标检测(Object Detection)
+ - 视频流目标检测:rtsp、摄像头、视频文件等
|
@@ -151,11 +152,40 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
|
+
+
+ 
+
+ |
-
+
- 自定义目标训练+检测
+ 语义分割 (Semantic Segmentation)
+
+ |
+
+
+ 
+
+ |
+
+
+
+
+ 实例分割 (Instance Segmentation)
+
+ |
+
+
+ 
+
+ |
+
+
+
+
+ 自定义目标训练+检测 (Object Detection)
|
@@ -167,7 +197,55 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
|
- OCR文字识别
+ 行人检测(Person Detection)
+
+ |
+
+
+ 
+
+ |
+
+
+
+
+ 人类动作识别 (Action Recognition)
+
+ |
+
+
+ 
+
+ |
+
+
+
+
+ OBB旋转框检测 (Oriented Bounding Boxes Object Detection)
+
+ |
+
+
+ 
+
+ |
+
+
+
+
+ 姿态估计 (Pose Estimation)
+
+ |
+
+
+ 
+
+ |
+
+
+
+
+ OCR文字识别 (Text Recognition)
- 支持任意角度文字识别
- 支持印刷体识别
- 支持手写字识别
@@ -183,7 +261,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
OCR文字识别
- - 表格识别
+ - 表格识别 (Table Structure Recognition)
|
@@ -195,7 +273,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
|
- 车牌识别
+ 车牌识别 (License Plate Recognition)
- 单层/双层检测
- 车牌颜色识别
@@ -214,7 +292,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
|
- 机器翻译
+ 机器翻译 (Machine Translation)
- 200多种语言互相翻译
|
@@ -227,7 +305,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
- 语音识别
+ 语音识别 (Speech Recognition)
- 支持100种语言
- 支持实时语音识别
@@ -243,13 +321,13 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
-## 🚀 核心亮点
+## 🚀 SmartJavaAI 解决了什么问题?
针对 Java 开发者在集成智能算法时常见的两大痛点:
- 🐍 主流AI深度学习框架(PyTorch/TensorFlow)的Python生态与Java工程体系割裂
-- ⚙️ 现有算法方案分散杂乱,封装不统一,使用门槛高,不易直接服务于 Java 业务开发
+- ⚙️ 现有AI集成方案分散杂乱,封装不统一,使用门槛高,不易直接服务于 Java 业务开发
我们实现了:
@@ -257,7 +335,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
✅ **支持多种深度学习引擎** - Pytorch、Tensorflow、MXNet、ONNX Runtime
-✅ **功能丰富** - 当前支持人脸识别与目标检测,未来将陆续支持 OCR、图像分类、NLP 等多个 AI 领域任务,构建全面的智能算法体系。
+✅ **功能丰富** - 当前支持人脸识别、目标检测、OCR、NLP 等多个 AI 领域任务,构建全面的智能算法体系。
✅ **跨平台兼容** - 支持Windows/Linux/macOS系统(x86 & ARM架构)
@@ -265,11 +343,8 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
## 📌 支持功能
-
-### ✅ 已实现功能
-
- **人脸识别**
- - 人脸检测:5点人脸关键点定位
+ - 人脸检测:人脸区域检测、5点人脸关键点定位
- 人脸识别:人脸512维特征提取、人脸对齐、1:1 人脸比对、1:N 人脸识别
- 人脸库:人脸注册、更新、查询、删除(支持向量数据库milvus/sqlite)
- 人脸属性检测:性别、年龄、口罩、眼睛状态、脸部姿态
@@ -277,8 +352,19 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
- 人脸表情识别:7种表情识别
- 人脸质量评估:亮度评估、清晰度评估、完整度评估、姿态评估、遮挡评估
- **目标检测**
- - 支持多种主流模型:兼容 YOLOv3、YOLOv5、YOLOv8、YOLOv11、YOLOv12、SSD 等目标检测算法
+ - 支持多种主流模型:集成 YOLOv5、YOLOv8、YOLOv11、YOLOv12、Tensorflow Object Detection 等目标检测算法
- 支持自定义模型加载:可无缝加载并部署用户自行训练的目标检测模型
+ - 集成行人检测模型
+- **语义分割**
+ - 集成DeepLabV3模型
+- **实例分割**
+ - 集成YOLOv8-seg、YOLOv11-seg、Mask R-CNN等模型
+- **OBB旋转框目标检测**
+ - 集成YOLOv11-obb模型
+- **动作识别**
+ - 支持KINETICS400数据集中400个人类动作识别
+- **姿态估计**
+ - 集成YOLOv8-pose、YOLOv11-pose等模型
- **OCR文字识别**
- 支持PaddleOCR 3.0模型:集成最新PP-OCRv5、PP-OCRv4、表格结构识别模型(SLANet_plus)、文本行方向分类模型
- 支持任意角度识别,方向校准
@@ -294,29 +380,29 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
## 🌟 AI集成方式对比
-| 方案 | 技术特点 | 优点 | 缺点 |
-|---------------------|--------------------------------------------------------------------------|---------------------------------------------------------------------|-----------------------------------------------|
-| **OpenCV** | 传统图像处理方案 | ✅ 提供java接口 ✅ 轻量级部署 ✅ 社区资源丰富 | ❌ 基于传统算法精度低(60%-75%) ❌ 需本地安装环境 |
+| 方案 | 技术特点 | 优点 | 缺点 |
+|---------------------|--------------------------------------------------------------------------|-------------------------------------------------------------------|-----------------------------------------------|
+| **OpenCV** | 传统图像处理方案 | ✅ 提供java接口 ✅ 轻量级部署 ✅ 社区资源丰富 | ❌ 基于传统算法精度低(60%-75%) ❌ 需本地安装环境 |
| **商业闭源SDK(如虹软等)** | 商业级闭源解决方案 | ✅ 开箱即用 ✅ 提供完整文档和SDK ✅ 支持离线活体检测 | ❌ 免费版需年度授权更新 ❌ 商业授权费用高 ❌ 代码不可控 |
| **云API(阿里云)** | SaaS化云端服务 | ✅ 零部署成本 ✅ 支持高并发 ✅ 自带模型迭代 | ❌ 网络延迟风险(200-800ms) ❌ 按调用量计费 ❌ 有数据安全风险 |
| **Python混合调用** | 跨语言调用方案 | ✅ 可集成PyTorch/TF等框架 ✅ 支持自定义算法 ✅ 识别精度高 | ❌ 需维护双语言环境 ❌ 进程通信性能损耗(30%+) ❌ 异常处理复杂度翻倍 |
-| **JNI/JNA** | 跨语言底层调用方案 | ✅ 直接调用 C/C++ 高性能算法库✅ 支持调用各种原生成熟库✅ 可封装成通用工具Jar | ❌ 开发成本高,JNI更复杂❌ 跨平台兼容性差 |
+| **JNI/JNA** | 跨语言底层调用方案 | ✅ 直接调用 C/C++ 高性能算法库 ✅ 支持调用各种原生成熟库 ✅ 可封装成通用工具Jar | ❌ 开发成本高,JNI更复杂 ❌ 跨平台兼容性差 |
| **DJL框架** | 深度学习框架 | ✅ 纯Java实现 ✅ 支持主流深度学习框架 ✅ 可加载预训练模型(99%+) | ❌ 需掌握DL知识 ❌ 需处理模型加载、预处理、后处理等复杂技术细节 |
-| **SmartJavaAI** | java深度学习工具包 | ✅ 支持主流深度学习框架 ✅ 提供丰富、开箱即用API ✅ 上手简单,单一Jar包集成 | 无 |
+| **SmartJavaAI** | java深度学习工具包 | ✅ 支持主流深度学习框架 ✅ 提供丰富、开箱即用API ✅ 上手简单,单一Jar包集成 | 无 |
## 🛠️包含组件
-| 模块 | 介绍 |
-|-----------------------------|------------------------------|
-| smartjavaai-common | 基础通用模块,封装了公共功能,供各算法模块共享使用 |
-| smartjavaai-bom | 依赖管理模块 |
-| smartjavaai-face | 人脸功能模块 |
-| smartjavaai-objectdetection | 目标检测模块 |
-| smartjavaai-ocr | OCR文字识别模块 |
-| smartjavaai-translate | 机器翻译模块 |
-| smartjavaai-speech | 语音功能模块,包含 ASR 和 TTS |
+| 模块 | 介绍 |
+|-----------------------|---------------------------|
+| common | 基础通用模块,封装了公共功能,供各算法模块共享使用 |
+| bom | 依赖管理模块 |
+| face | 人脸功能模块 |
+| vision | 通用视觉模块(目标检测等功能) |
+| ocr | OCR文字识别模块 |
+| translate | 机器翻译模块 |
+| speech | 语音功能模块,包含 ASR 和 TTS |
可以根据需求对每个模块单独引入,也可以通过引入`smartjavaai-all`方式引入所有模块。
@@ -335,10 +421,14 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
### 1、环境要求
- Java 版本:**JDK 8或更高版本**
-- 操作系统:不同模型支持的系统不一样,具体请查看文档
+- 操作系统:不同模型支持的系统不一样,具体请查看[文档](http://doc.smartjavaai.cn)
### 2、Maven
-在项目的pom.xml的dependencies中加入以下内容(全部功能),也可以根据需求对每个模块单独引入:
+
+在项目的 `pom.xml` 的 `dependencies` 中可以一次性引入全部功能(如下所示)。
+⚠️ **注意:不推荐直接引入全部依赖**,更推荐根据实际需求,按功能模块单独引入,避免引入不必要的包。
+
+详细引入方式请查看 [文档](http://doc.smartjavaai.cn/Install)、或查看[示例代码](https://gitee.com/dengwenjie/SmartJavaAI/tree/master/examples)
```xml
@@ -347,6 +437,7 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
1.0.24
```
+
### 3、完整示例代码
[示例代码](https://gitee.com/dengwenjie/SmartJavaAI/tree/master/examples)
@@ -363,39 +454,33 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
**人脸检测模型(FaceDetection、FaceLandmarkExtraction)**
-支持功能:
-- 人脸检测
-- 5点人脸关键点定位
-
-| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
-| ----------- |---------|-------------------------|----------------------------------------------------------------------------------------|
-| RetinaFace | PyTorch | 高精度人脸检测模型 | [Github](https://github.com/biubug6/Pytorch_Retinaface) |
-| UltraLightFastGenericFace | PyTorch | 针对边缘计算设备设计的轻量人脸检测模型 | [Github](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB) |
-| SeetaFace6 | C++ | 中科视拓最新开放的开源免费的全栈人脸识别工具包 | [Github](https://github.com/seetafaceengine/SeetaFace6) |
+| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
+|------------------------------|-------------|------------------------------|---------------------------------------------------------------------------------|
+| MTCNN(均衡) | PyTorch | 使用最广泛的模型之一,经典多阶段人脸检测,速度与精度均衡 | [Github](https://github.com/timesler/facenet-pytorch) |
+| SeetaFace6(均衡模型) | C++ | 中科视拓最新开放的开源免费的全栈人脸识别工具包 | [Github](https://github.com/seetafaceengine/SeetaFace6) |
+| RetinaFace(高精度) | PyTorch | 基于单阶段检测的多尺度人脸检测 | [Github](https://github.com/biubug6/Pytorch_Retinaface) |
+| RetinaFace_1080x720(高精度) | OnnxRuntime | 针对高分辨率图像优化的 RetinaFace 模型 | [Github](https://github.com/biubug6/Pytorch_Retinaface) |
+| RetinaFace_640x640(高精度) | OnnxRuntime | 针对低分辨率图像优化的 RetinaFace 模型 | [Github](https://github.com/biubug6/Pytorch_Retinaface) |
+| yolov5face_n_0.5_320x320(极速) | OnnxRuntime | YOLOv5 小型人脸检测模型,设计轻量,适合快速推理 | 无 |
+| yolov5face_m_640x640(极速) | OnnxRuntime | YOLOv5 中型人脸检测模型 | 无 |
+| UltraLightFastGenericFace(极速) | PyTorch | 针对边缘计算设备设计的轻量人脸检测模型 | [Github](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB) |
---
**人脸识别模型(FaceRecognition)**
-支持功能:
-- 人脸512维特征提取
-- 人脸对齐(人脸矫正)
-- 人脸特征比对(内积[IP]、欧氏距离[L2]、余弦相似度[COSINE])
-| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
-|-------|---------|---------------------------------------------------------|----------------------------------------------------------------------------------------|
-| InsightFace_IR-SE50| PyTorch | (高精度)这是对 ArcFace(论文)和 InsightFace(GitHub)的 PyTorch 重新实现 | [Github](https://github.com/TreB1eN/InsightFace_Pytorch) |
-| InsightFace_Mobilefacenet | PyTorch | (轻量级)这是对 ArcFace(论文)和 InsightFace(GitHub)的 PyTorch 重新实现 | [Github](https://github.com/TreB1eN/InsightFace_Pytorch) |
-| FaceNet | PyTorch | 基于 PyTorch 的 Inception ResNet(V1)模型仓库 | [Github](https://github.com/timesler/facenet-pytorch) |
-| ElasticFace| PyTorch | 基于 CVPRW2022 论文《ElasticFace: Elastic Margin Loss for Deep Face Recognition》实现的人脸识别模型| [Github](https://github.com/fdbtrs/ElasticFace) |
-| SeetaFace6 | C++ | 中科视拓最新开放的开源免费的全栈人脸识别工具包 | [Github](https://github.com/seetafaceengine/SeetaFace6) |
+| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
+|-------------------------------|---------|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
+| InsightFace_IR-SE50(高精度) | PyTorch | 这是对 ArcFace(论文)和 InsightFace(GitHub)的 PyTorch 重新实现 | [Github](https://github.com/TreB1eN/InsightFace_Pytorch) |
+| InsightFace_Mobilefacenet(极速) | PyTorch | (轻量级)这是对 ArcFace(论文)和 InsightFace(GitHub)的 PyTorch 重新实现 | [Github](https://github.com/TreB1eN/InsightFace_Pytorch) |
+| FaceNet(均衡) | PyTorch | 基于 PyTorch 的 Inception ResNet(V1)模型仓库 | [Github](https://github.com/timesler/facenet-pytorch) |
+| ElasticFace(高精度) | PyTorch | 基于 CVPRW2022 论文《ElasticFace: Elastic Margin Loss for Deep Face Recognition》实现的人脸识别模型 | [Github](https://github.com/fdbtrs/ElasticFace) |
+| SeetaFace6(均衡) | C++ | 中科视拓最新开放的开源免费的全栈人脸识别工具包 | [Github](https://github.com/seetafaceengine/SeetaFace6) |
**静态活体检测(RGB)模型(Silent face-anti-spoofing、FaceLivenessDetection)**
-支持功能:
-- 检测图片中的人脸是否为来自认证设备端的近距离裸拍活体人脸对象(裸拍活体正面人脸是指真人未经重度PS、风格化、人工合成等后处理的含正面人脸)
-
| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
|-----------|----------------|-------------------------|----------------------------------------------------------------------|
| MiniVision| OnnxRuntime | 小视科技的静默活体检测 | [Github](https://github.com/minivision-ai/Silent-Face-Anti-Spoofing) |
@@ -446,21 +531,23 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
#### 目标检测模型
-支持功能:
-- 自训练模型推理
-- yolov3~yolov12 系列
-
**YOLO 系列**
-|模型名称 | 引擎 | 版本 | 大小(Backbone) | 数据集 | 精度 | 速度 | 适用场景 |
-| :---------- |-------------| -------| ----------- |----------------------------------------|-----------------------------------|-------|--------------------------------------|
-| YOLO12N | OnnxRuntime | v12 | 极轻量 | COCO | 高 | 极快 | YOLO 系列最新版本,精度与速度进一步优化,适合高实时性要求场景 |
-|YOLO11N | PyTorch | v11 | 极轻量 | COCO | 中等偏上 | 极快 | 与 v8n 类似,版本更新点在兼容性与 API |
-|YOLOV8N | PyTorch | v8 | 极轻量 | COCO | 中等偏上 | 极快 | 对实时性要求极高的应用 |
-|YOLOV5S | PyTorch | v5 | 小型 | COCO | 较高 | 非常快 | 常见通用场景,算力资源有限时优选 |
-|YOLOV5S_ONNXRUNTIME| OnnxRuntime | v5 | 小型 | COCO | 较高 | 加速(需 ONNX 支持) | Windows/Linux 通用加速部署 |
-|YOLO (MXNet / 通用模型) | MXNet | v3 | DarkNet‑53 | COCO | 较高 | 快 | 需要 MXNet 生态或复现老项目时使用 |
+| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
+|---------|----------------|-------------------------|----------------------------------------------------------------------|
+| YOLOV12 | OnnxRuntime | 最流行的目标检测模型 | [Github](https://docs.ultralytics.com/zh/models/) |
+| YOLOV11 | OnnxRuntime | 最流行的目标检测模型 | [Github](https://docs.ultralytics.com/zh/models/) |
+| YOLOV8 | OnnxRuntime | 最流行的目标检测模型 | [Github](https://docs.ultralytics.com/zh/models/) |
+**Tensorflow系列**
+
+仅测试了以下Tensorflow目标检测模型
+
+| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
+|---------|-------------|----------------|----------------------------------------------------------------------|
+| EfficientDet | Tensorflow | Tensorflow目标检测 | [Github](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md) |
+| SSD MobileNet V2 | Tensorflow | Tensorflow目标检测 | [Github](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md) |
+| Faster RCNN Inception Resnet V2 | Tensorflow | Tensorflow目标检测 | [Github](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md) |
**SSD 系列**
@@ -472,21 +559,59 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
|SSD_300_VGG16_ATROUS_VOC| MXNet | VGG‑16 | 300×300 | Pascal VOC | 中等偏上 | 快 | VOC 数据集同类任务;资源受限时使用|
|SSD_512_MOBILENET1_VOC| MXNet | MobileNet‑1.0 | 512×512 | Pascal VOC | 中等 | 快 | 嵌入式/移动端设备;算力和内存都很有限|
+---
-**YOLOv3 变体系列**
+#### 语义分割模型
-|模型名称| 引擎 | 骨干网络 | 数据集 | 输入尺寸 | 精度 | 速度 | 适用场景 |
-| :-----|---------- | -------| ----------- |------------| ---------|-------|--------------------------------------|
-|YOLO3_DARKNET_VOC_416|MXNet | DarkNet‑53 | VOC | 416×416 | 高 | 中等 | VOC 任务复现;精度优先 |
-|YOLO3_DARKNET_COCO_320 |MXNet| DarkNet‑53 | COCO | 320×320 | 中等 | 快 | COCO 小模型测试;资源受限 |
-|YOLO3_DARKNET_COCO_416 |MXNet| DarkNet‑53 | COCO | 416×416 | 高 | 中等 | 通用 COCO 部署;精度优先 |
-|YOLO3_DARKNET_COCO_608 |MXNet| DarkNet‑53 | COCO | 608×608 | 很高 | 慢| 批量离线推理;精度要求极高 |
-|YOLO3_MOBILENET_VOC_320 |MXNet| MobileNet‑V1 | VOC | 320×320 | 中等 | 非常快| 嵌入式设备;VOC 小目标任务 |
-|YOLO3_MOBILENET_VOC_416 |MXNet| MobileNet‑V1 | VOC | 416×416 | 高 | 快| 移动端 VOC 部署 |
-|YOLO3_MOBILENET_COCO_320 |MXNet| MobileNet‑V1 | COCO | 320×320 | 中等 | 非常快 | 嵌入式设备;COCO 小目标任务 |
-|YOLO3_MOBILENET_COCO_416 |MXNet| MobileNet‑V1 | COCO | 416×416 | 高 | 快 | 移动端 COCO 部署 |
-|YOLO3_MOBILENET_COCO_608 |MXNet| MobileNet‑V1 | COCO | 608×608 | 很高 | 中等 | 对精度要求较高的移动端任务 |
+| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
+|---------|---------|-------------------------|--------|
+| DeepLabv3 | PyTorch | DeepLabv3 是一种图像分割模型,可以把图片里的每个像素分类出来 | 无 |
+---
+
+#### 实例分割模型
+
+
+| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
+|-------------|---------|------------------------------------|------------|
+| YOLOV8-SEG | OnnxRuntime | Ultralytics在COCO 数据集 上训练的模型 | [Github](https://docs.ultralytics.com/zh/tasks/segment/) |
+| YOLOV11-SEG | OnnxRuntime | Ultralytics在COCO 数据集 上训练的模型 | [Github](https://docs.ultralytics.com/zh/tasks/segment/) |
+| Mask R-CNN | MXNet | Mask R-CNN 是一种在目标检测基础上,同时为每个物体生成像素级分割区域的深度学习模型 | 无 |
+---
+
+#### OBB旋转框目标检测模型
+
+| 模型名称 | 引擎 | 模型简介 | 模型开源网站 |
+|-------------|---------|--------------------------------|------------|
+| YOLOV11-OBB | OnnxRuntime | Ultralytics在DOTAv1 数据集 上训练的模型、通过引入一个额外的角度来更准确地定位图像中的对象 | [Github](https://docs.ultralytics.com/zh/tasks/segment/) |
+---
+
+#### 行人检测模型
+
+| 模型名称 | 引擎 | 模型开源网站 |
+|-------------|---------|-----|
+| YOLOV8_PERSON | OnnxRuntime | [Github](https://github.com/YapaLab/yolo-face) |
+
+---
+
+#### 人类动作识别模型
+
+| 模型名称 | 引擎 |
+|-------------|---------|
+| VIT_BASE_PATCH16 | PyTorch |
+| INCEPTIONV3_KINETICS400 | OnnxRuntime |
+| INCEPTIONV1_KINETICS400 | OnnxRuntime |
+| RESNET_V1B_KINETICS400 | OnnxRuntime |
+---
+
+#### 姿态估计模型
+
+
+| 模型名称 | 引擎 | 模型开源网站 |
+|--------------|-------------|----------------------------------------------------------|
+| YOLO11N-POSE | OnnxRuntime | [Github](https://docs.ultralytics.com/zh/tasks/pose/) |
+| YOLO8N-POSE | OnnxRuntime | [Github](https://docs.ultralytics.com/zh/tasks/pose/) |
+| SIMPLE_POSE | MXNet | 无 |
---
#### OCR 模型
@@ -555,9 +680,11 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
支持功能
- 200多语言互相翻译
-| 模型名称 | 模型简介 | 模型官网 |
-| ------------------------------ | ------------------------ |-----------------------------------------------|
-| NLLB-200 | Meta AI 开发的一个先进的单一多语言机器翻译模型 | [Github](https://github.com/facebookresearch/fairseq/tree/nllb) |
+| 模型名称 | 模型简介 | 模型官网 |
+|---------------|-----------------------------------------|-----------------------------------------------|
+| NLLB-200 | Meta AI 开发的一个先进的单一多语言机器翻译模型 | [Github](https://github.com/facebookresearch/fairseq/tree/nllb) |
+| OPUS_MT_ZH_EN | Helsinki-NLP团队开发的中英翻译模型,基于Transformer架构 | [huggingface](https://huggingface.co/Helsinki-NLP/opus-mt-zh-en) |
+| OPUS_MT_EN_ZH | Helsinki-NLP团队开发的英中翻译模型,基于Transformer架构 | [huggingface](https://huggingface.co/Helsinki-NLP/opus-mt-en-zh) |
---
@@ -606,7 +733,19 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
## 近期更新日志
-## [v1.0.24] - 2025-08-09
+## [v1.0.24] - 2025-09-07
+- 【人脸检测】新增6个模型(MTCNN、YOLOV5、RetinaFace小尺寸版),大幅提升性能
+- 【人脸识别】新增Seetaface6轻量模型
+- 【目标检测】支持视频流目标检测(rtsp、视频文件等)
+- 【目标检测】支持tensorflow2目标检测模型
+- 【目标检测】新增行人检测模型(yolo-person)
+- 【通用视觉】新增4个动作识别模型
+- 【通用视觉】新增语义分割模型
+- 【通用视觉】新增5个实例分割模型(含yolov8-seg、yolov11-seg)
+- 【通用视觉】新增yolo-obb11旋转框检测(含yolov11-obb)
+- 【通用视觉】新增5个姿态估计模型(含yolov8-pose、yolov11-pose)
+
+## [v1.0.23] - 2025-08-09
- 新增 语音识别模块,集成 OpenAI 开源的 Whisper 和 Vosk
- 修复 质量评估模型的 Bug
- 修复 OCR 模块 recognizeAndDraw 方法的 Bug
@@ -628,17 +767,3 @@ SmartJavaAI是专为JAVA 开发者打造的一个功能丰富、开箱即用的
- 人脸识别:支持ID查询及分页获取人脸信息
- 活体检测:视频检测支持设置最大帧数
-## [v1.0.19] - 2025-07-06
-- 人脸模块:新增小视科技(MiniVision)活体检测模型
-- 人脸模块:新增阿里通义工作室活体检测模型
-- 人脸模块:新增 2 个表情识别模型
-- 人脸模块:新增 InsightFace 和 ElasticFace 人脸识别模型
-- 人脸模块:新增 Seetaface6 质量评估模型
-- 目标检测模块:支持更多自定义模型参数配置
-- 人脸模块:支持 Base64 编码图片输入
-- 通用功能:实现 AutoCloseable 接口,支持资源自动释放
-- OCR 模块:修复加方向矫正后无法连续识别的问题
-- 人脸模块:修复人脸更新后的缓存异常问题
-- 其他:优化部分功能与细节体验
-
-
diff --git a/common/src/main/java/cn/smartjavaai/common/entity/DetectionResponse.java b/common/src/main/java/cn/smartjavaai/common/entity/DetectionResponse.java
index a0df61e..9aaa0f7 100644
--- a/common/src/main/java/cn/smartjavaai/common/entity/DetectionResponse.java
+++ b/common/src/main/java/cn/smartjavaai/common/entity/DetectionResponse.java
@@ -8,14 +8,13 @@ import java.util.List;
/**
* 检测结果
* @author dwj
- * @date 2025/4/12
*/
@Data
public class DetectionResponse {
private List detectionInfoList;
- private Image drawnImage;
+ private transient Image drawnImage;
public DetectionResponse() {
diff --git a/common/src/main/java/cn/smartjavaai/common/entity/ObbDetInfo.java b/common/src/main/java/cn/smartjavaai/common/entity/ObbDetInfo.java
index 7490df3..2836971 100644
--- a/common/src/main/java/cn/smartjavaai/common/entity/ObbDetInfo.java
+++ b/common/src/main/java/cn/smartjavaai/common/entity/ObbDetInfo.java
@@ -1,11 +1,14 @@
package cn.smartjavaai.common.entity;
+import lombok.Data;
+
import java.util.List;
/**
* 定向边界框 检测结果
* @author dwj
*/
+@Data
public class ObbDetInfo {
/**
diff --git a/common/src/main/java/cn/smartjavaai/common/utils/FrameConverterUtil.java b/common/src/main/java/cn/smartjavaai/common/utils/FrameConverterUtil.java
deleted file mode 100644
index b2ac439..0000000
--- a/common/src/main/java/cn/smartjavaai/common/utils/FrameConverterUtil.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package cn.smartjavaai.common.utils;
-
-import ai.djl.modality.cv.Image;
-import ai.djl.modality.cv.ImageFactory;
-import org.bytedeco.javacpp.BytePointer;
-import org.bytedeco.javacv.OpenCVFrameConverter;
-import org.bytedeco.opencv.opencv_core.CvMat;
-import org.bytedeco.opencv.opencv_core.Mat;
-import org.opencv.core.CvType;
-
-import java.awt.image.BufferedImage;
-
-/**
- * @author dwj
- * @date 2025/8/27
- */
-public class FrameConverterUtil {
-
- /**
- * 将 Bytedeco Mat 转为 DJL Image
- * 支持 1/3/4 通道
- */
- public static Image matToDJLImage(Mat cvMat) {
- if (cvMat == null || cvMat.empty()) {
- return null;
- }
-
- int width = cvMat.cols();
- int height = cvMat.rows();
- int channels = cvMat.channels();
-
- int[] pixels = new int[width * height];
-
- if (channels == 1) { // 灰度图
- byte[] data = new byte[width * height];
- cvMat.data().get(data);
- for (int i = 0; i < width * height; i++) {
- int gray = data[i] & 0xFF;
- pixels[i] = (0xFF << 24) | (gray << 16) | (gray << 8) | gray;
- }
- } else if (channels == 3) { // BGR
- byte[] data = new byte[width * height * 3];
- cvMat.data().get(data);
- for (int i = 0; i < width * height; i++) {
- int b = data[i * 3] & 0xFF;
- int g = data[i * 3 + 1] & 0xFF;
- int r = data[i * 3 + 2] & 0xFF;
- pixels[i] = (0xFF << 24) | (r << 16) | (g << 8) | b;
- }
- } else if (channels == 4) { // BGRA
- byte[] data = new byte[width * height * 4];
- cvMat.data().get(data);
- for (int i = 0; i < width * height; i++) {
- int b = data[i * 4] & 0xFF;
- int g = data[i * 4 + 1] & 0xFF;
- int r = data[i * 4 + 2] & 0xFF;
- int a = data[i * 4 + 3] & 0xFF;
- pixels[i] = (a << 24) | (r << 16) | (g << 8) | b;
- }
- } else {
- throw new IllegalArgumentException("只支持 1/3/4 通道图像");
- }
-
- return ImageFactory.getInstance().fromPixels(pixels, width, height);
- }
-}
diff --git a/common/src/main/java/cn/smartjavaai/common/utils/ImageUtils.java b/common/src/main/java/cn/smartjavaai/common/utils/ImageUtils.java
index e0b6344..e925453 100644
--- a/common/src/main/java/cn/smartjavaai/common/utils/ImageUtils.java
+++ b/common/src/main/java/cn/smartjavaai/common/utils/ImageUtils.java
@@ -3,8 +3,11 @@ package cn.smartjavaai.common.utils;
import ai.djl.modality.cv.BufferedImageFactory;
import ai.djl.modality.cv.Image;
import ai.djl.modality.cv.ImageFactory;
+import ai.djl.modality.cv.output.CategoryMask;
import ai.djl.modality.cv.output.DetectedObjects;
import ai.djl.ndarray.NDArray;
+import ai.djl.util.RandomUtils;
+import cn.smartjavaai.common.cv.SmartImageFactory;
import cn.smartjavaai.common.entity.DetectionRectangle;
import cn.smartjavaai.common.entity.DetectionResponse;
import org.opencv.core.Mat;
@@ -17,6 +20,7 @@ import java.awt.*;
import java.awt.image.BufferedImage;
//import java.awt.image.ColorConvertOp;
import java.awt.image.ComponentSampleModel;
+import java.awt.image.DataBufferByte;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;
@@ -500,6 +504,86 @@ public class ImageUtils {
}
+ /**
+ * 拷贝图片
+ * @param src
+ * @return
+ */
+ public static BufferedImage copyBufferedImage(BufferedImage src) {
+ BufferedImage copy = new BufferedImage(src.getWidth(), src.getHeight(), src.getType());
+ Graphics2D g = copy.createGraphics();
+ g.drawImage(src, 0, 0, null);
+ g.dispose();
+ return copy;
+ }
+
+
+ /**
+ * 拷贝图片
+ * @param src
+ * @return
+ */
+ public static Image copy(Image src) {
+ Object srcData = src.getWrappedImage();
+ //当图片未BufferedImage,DJL的duplicate会有问题
+ if (srcData instanceof BufferedImage) {
+ return SmartImageFactory.getInstance().fromImage(copyBufferedImage((BufferedImage) srcData));
+ }else{
+ return src.duplicate();
+ }
+ }
+
+ /**
+ * 为不同分类生成不同颜色
+ * @param background
+ * @param opacity
+ * @param classes
+ * @return
+ */
+ public static int[] generateColors(int background, int opacity, List classes) {
+ int[] colors = new int[classes.size()];
+ colors[0] = background;
+ for (int i = 1; i < classes.size(); i++) {
+ int red = RandomUtils.nextInt(256);
+ int green = RandomUtils.nextInt(256);
+ int blue = RandomUtils.nextInt(256);
+ colors[i] = opacity << 24 | red << 16 | green << 8 | blue;
+ }
+ return colors;
+ }
+
+ /**
+ * 生成不同颜色遮罩
+ * @param colors
+ * @param mask
+ * @return
+ */
+ public static Image getColorOverlay(int[] colors,int[][] mask) {
+ int height = mask.length;
+ int width = mask[0].length;
+ int[] pixels = new int[width * height];
+ for (int h = 0; h < height; h++) {
+ for (int w = 0; w < width; w++) {
+ int index = mask[h][w];
+ pixels[h * width + w] = colors[index];
+ }
+ }
+ return SmartImageFactory.getInstance().fromPixels(pixels, width, height);
+ }
+
+ /**
+ * 绘制遮罩
+ * @param categoryMask
+ * @param image
+ * @param opacity
+ * @param background
+ */
+ public static void drawMask(CategoryMask categoryMask, Image image, int opacity, int background) {
+ int[] colors = generateColors(background, opacity, categoryMask.getClasses());
+ Image maskImage = getColorOverlay(colors, categoryMask.getMask());
+ image.drawImage(maskImage, true);
+ }
+
diff --git a/common/src/main/java/cn/smartjavaai/common/utils/OpenCVUtils.java b/common/src/main/java/cn/smartjavaai/common/utils/OpenCVUtils.java
index ea782d1..909cf6a 100644
--- a/common/src/main/java/cn/smartjavaai/common/utils/OpenCVUtils.java
+++ b/common/src/main/java/cn/smartjavaai/common/utils/OpenCVUtils.java
@@ -239,27 +239,27 @@ public class OpenCVUtils {
* @param src Bytedeco Mat (BGR 或 BGRA)
* @return OpenCV Mat (BGR 或 BGRA)
*/
- public static org.opencv.core.Mat convertToOpenCVMat(org.bytedeco.opencv.opencv_core.Mat bMat) {
-
-
- try {
- int width = bMat.cols();
- int height = bMat.rows();
- int channels = bMat.channels();
-
- // 创建 OpenCV Mat
- org.opencv.core.Mat cvMat = new org.opencv.core.Mat(height, width, channels == 3 ? CvType.CV_8UC3 : CvType.CV_8UC1);
-
- // 从 bytedeco Mat 获取像素数据
- byte[] data = new byte[width * height * channels];
- bMat.data().get(data);
-
- // 填充到 OpenCV Mat
- cvMat.put(0, 0, data);
- return cvMat;
- } catch (Throwable e) {
- e.printStackTrace();
- }
- return null;
- }
+// public static org.opencv.core.Mat convertToOpenCVMat(org.bytedeco.opencv.opencv_core.Mat bMat) {
+//
+//
+// try {
+// int width = bMat.cols();
+// int height = bMat.rows();
+// int channels = bMat.channels();
+//
+// // 创建 OpenCV Mat
+// org.opencv.core.Mat cvMat = new org.opencv.core.Mat(height, width, channels == 3 ? CvType.CV_8UC3 : CvType.CV_8UC1);
+//
+// // 从 bytedeco Mat 获取像素数据
+// byte[] data = new byte[width * height * channels];
+// bMat.data().get(data);
+//
+// // 填充到 OpenCV Mat
+// cvMat.put(0, 0, data);
+// return cvMat;
+// } catch (Throwable e) {
+// e.printStackTrace();
+// }
+// return null;
+// }
}
diff --git a/common/src/main/java/cn/smartjavaai/common/utils/VideoUtils.java b/common/src/main/java/cn/smartjavaai/common/utils/VideoUtils.java
deleted file mode 100644
index d43ddda..0000000
--- a/common/src/main/java/cn/smartjavaai/common/utils/VideoUtils.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package cn.smartjavaai.common.utils;
-
-import org.bytedeco.ffmpeg.global.avcodec;
-import org.bytedeco.javacv.FFmpegFrameGrabber;
-import org.bytedeco.javacv.FFmpegFrameRecorder;
-import org.bytedeco.javacv.Frame;
-import org.bytedeco.javacv.OpenCVFrameConverter;
-import org.bytedeco.opencv.global.opencv_core;
-import org.bytedeco.opencv.opencv_core.Mat;
-
-/**
- * 视频工具类
- * @author dwj
- * @date 2025/7/17
- */
-public class VideoUtils {
-
- /**
- * 视频旋转
- * @param inputPath 输入视频路径
- * @param outputPath 输出视频路径
- * @param angle 旋转角度
- * @param format 视频格式
- * @param videoCodec 视频编码器
- * @throws FFmpegFrameRecorder.Exception
- * @throws FFmpegFrameGrabber.Exception
- */
- public static void rotateVideo(String inputPath, String outputPath, int angle, String format, int videoCodec) throws FFmpegFrameRecorder.Exception, FFmpegFrameGrabber.Exception {
- FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputPath);
- grabber.start();
- int inputWidth = grabber.getImageWidth();
- int inputHeight = grabber.getImageHeight();
- int outputWidth = inputWidth;
- int outputHeight = inputHeight;
-
- if (angle == 90 || angle == 270) {
- outputWidth = inputHeight;
- outputHeight = inputWidth;
- }
- FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputPath,
- outputWidth, outputHeight, grabber.getAudioChannels());
- recorder.setVideoCodec(videoCodec);
- recorder.setFormat(format);
- recorder.start();
- Frame frame;
- OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
- while ((frame = grabber.grab()) != null) {
- if (frame.image != null) {
- Mat mat = converter.convert(frame);
- Mat rotated = new Mat();
- switch (angle) {
- case 90:
- opencv_core.transpose(mat, rotated);
- opencv_core.flip(rotated, rotated, 1);
- break;
- case 180:
- opencv_core.flip(mat, rotated, -1);
- break;
- case 270:
- opencv_core.transpose(mat, rotated);
- opencv_core.flip(rotated, rotated, 0);
- break;
- default:
- rotated = mat.clone();
- break;
- }
- frame = converter.convert(rotated);
- recorder.record(frame);
- }
- }
- recorder.stop();
- recorder.release();
- grabber.stop();
- grabber.release();
- }
-
-}
diff --git a/examples/face-example/pom.xml b/examples/face-example/pom.xml
index 5562054..08db1dd 100644
--- a/examples/face-example/pom.xml
+++ b/examples/face-example/pom.xml
@@ -55,11 +55,7 @@
commons-io
2.17.0
-
- org.apache.logging.log4j
- log4j-slf4j2-impl
- 2.24.1
-
+
org.testng
testng
@@ -73,11 +69,6 @@
logback-classic
1.2.3
-
- org.slf4j
- slf4j-api
- 1.7.30
-
com.alibaba
@@ -101,7 +92,7 @@
ai.djl.pytorch
pytorch-jni
- 2.7.1-0.34.0
+ 2.5.1-0.32.0
runtime
@@ -138,7 +129,7 @@
ai.djl.pytorch
pytorch-native-cpu
${djl.platform.windows-x86_64}
- 2.7.1
+ 2.5.1
runtime
@@ -176,9 +167,18 @@
ai.djl.pytorch
pytorch-native-cpu
${djl.platform.linux-x86_64}
- 2.7.1
+ 2.5.1
runtime
+
+ ai.djl.pytorch
+ pytorch-native-cpu-precxx11
+ ${djl.platform.linux-x86_64}
+ 2.5.1
+ runtime
+
+
+
@@ -213,11 +213,13 @@
ai.djl.pytorch
pytorch-native-cpu
${djl.platform.osx-aarch64}
- 2.7.1
+ 2.5.1
runtime
+
+
org.bytedeco
@@ -247,22 +249,6 @@
${javacv.platform.linux-arm64}
-
- ai.djl.pytorch
- pytorch-native-cpu-precxx11
- ${djl.platform.linux-aarch64}
- 2.5.1
- runtime
-
-
-
- ai.djl.pytorch
- pytorch-native-cpu
- linux-aarch64
- runtime
- 2.7.1
-
-
@@ -294,16 +280,10 @@
- aliyunmaven
- 阿里云公共仓库
- https://maven.aliyun.com/repository/public
-
- true
-
-
- false
-
+ central
+ https://repo1.maven.org/maven2/
+
diff --git a/examples/face-example/src/main/java/smartai/examples/face/PythonTranslator.java b/examples/face-example/src/main/java/smartai/examples/face/PythonTranslator.java
deleted file mode 100644
index 542118c..0000000
--- a/examples/face-example/src/main/java/smartai/examples/face/PythonTranslator.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
- * with the License. A copy of the License is located at
- *
- * http://aws.amazon.com/apache2.0/
- *
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
- * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
- * and limitations under the License.
- */
-package smartai.examples.face;
-
-import ai.djl.ModelException;
-import ai.djl.inference.Predictor;
-import ai.djl.modality.Classifications;
-import ai.djl.modality.Input;
-import ai.djl.modality.Output;
-import ai.djl.modality.cv.Image;
-import ai.djl.ndarray.NDList;
-import ai.djl.repository.zoo.Criteria;
-import ai.djl.repository.zoo.ZooModel;
-import ai.djl.translate.NoBatchifyTranslator;
-import ai.djl.translate.TranslateException;
-import ai.djl.translate.TranslatorContext;
-import ai.djl.util.JsonUtils;
-import ai.djl.util.Utils;
-
-import com.google.gson.reflect.TypeToken;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Type;
-import java.net.URL;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public class PythonTranslator implements NoBatchifyTranslator {
-
- private ZooModel model;
- private Predictor predictor;
-
- @Override
- public void prepare(TranslatorContext ctx) throws ModelException, IOException {
- if (predictor == null) {
- Criteria criteria =
- Criteria.builder()
- .setTypes(Input.class, Output.class)
- .optModelPath(Paths.get("src/test/python"))
- .optEngine("Python")
- .build();
- model = criteria.loadModel();
- predictor = model.newPredictor();
- }
- }
-
-// @Override
-// public NDList processInput(TranslatorContext ctx, String url)
-// throws IOException, TranslateException {
-// Input input = new Input();
-// try (InputStream is = new URL(url).openStream()) {
-// input.add("data", Utils.toByteArray(is));
-// }
-// input.addProperty("Content-Type", "image/jpeg");
-// // calling preprocess() function in model.py
-// input.addProperty("handler", "preprocess");
-// Output output = predictor.predict(input);
-// if (output.getCode() != 200) {
-// throw new TranslateException("Python preprocess() failed: " + output.getMessage());
-// }
-//
-// return output.getDataAsNDList(ctx.getNDManager());
-// }
-
- @Override
- public NDList processInput(TranslatorContext ctx, byte[] image)
- throws IOException, TranslateException {
- Input input = new Input();
- input.add("data", image);
- input.addProperty("Content-Type", "image/jpeg");
- // calling preprocess() function in model.py
- input.addProperty("handler", "preprocess");
- Output output = predictor.predict(input);
- if (output.getCode() != 200) {
- throw new TranslateException("Python preprocess() failed: " + output.getMessage());
- }
- return output.getDataAsNDList(ctx.getNDManager());
- }
-
- @Override
- public Classifications processOutput(TranslatorContext ctx, NDList list)
- throws TranslateException {
- Input input = new Input();
- input.add("data", list);
- // calling postprocess() function in processing.py
- input.addProperty("handler", "postprocess");
- Output output = predictor.predict(input);
- if (output.getCode() != 200) {
- throw new TranslateException("Python postprocess() failed: " + output.getMessage());
- }
-
- String json = output.getData().getAsString();
- System.out.println("json:" + json);
- return null;
- }
-
- public void close() {
- if (predictor != null) {
- predictor.close();
- model.close();
- predictor = null;
- model = null;
- }
- }
-}
diff --git a/examples/face-example/src/main/java/smartai/examples/face/Test.java b/examples/face-example/src/main/java/smartai/examples/face/Test.java
deleted file mode 100644
index 67b3870..0000000
--- a/examples/face-example/src/main/java/smartai/examples/face/Test.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package smartai.examples.face;
-
-import ai.djl.Application;
-import ai.djl.Device;
-import ai.djl.MalformedModelException;
-import ai.djl.inference.Predictor;
-import ai.djl.modality.Classifications;
-import ai.djl.modality.audio.Audio;
-import ai.djl.modality.audio.AudioFactory;
-import ai.djl.modality.audio.translator.SpeechRecognitionTranslatorFactory;
-import ai.djl.repository.Artifact;
-import ai.djl.repository.MRL;
-import ai.djl.repository.zoo.Criteria;
-import ai.djl.repository.zoo.ModelNotFoundException;
-import ai.djl.repository.zoo.ModelZoo;
-import ai.djl.repository.zoo.ZooModel;
-import ai.djl.translate.TranslateException;
-import lombok.extern.slf4j.Slf4j;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author dwj
- * @date 2025/7/29
- */
-@Slf4j
-public class Test {
-
- public static void main(String[] args) throws ModelNotFoundException, MalformedModelException, IOException, TranslateException {
-// PythonTranslator translator = new PythonTranslator();
-// Criteria criteria =
-// Criteria.builder()
-// .setTypes(byte[].class, Classifications.class)
-// .optModelPath(Paths.get("/Users/wenjie/Documents/develop/model/arcfaceresnet100-11-int8.onnx"))
-// .optEngine("OnnxRuntime")
-// .optTranslator(translator)
-// .build();
-// String path = "/Users/wenjie/Downloads/facetest/jsy.jpg";
-// try (ZooModel model = criteria.loadModel();
-// Predictor predictor = model.newPredictor()) {
-// byte[] data = Files.readAllBytes(Paths.get(path));
-// Classifications ret = predictor.predict(data);
-// System.out.println(ret);
-// }
-//
-// // unload python model
-// translator.close();
-
-
- // Load model.
- // Wav2Vec2 model is a speech model that accepts a float array corresponding to the raw
- // waveform of the speech signal.
-
-// String url = "/Users/wenjie/Downloads/20210601_u2++_conformer_exp/final.pt";
-// Criteria | | |