1、集成车牌识别模型,支持车牌检测与识别
2、新增 Milvus 身份验证支持 3、目标检测功能升级:可指定类别及topk 4、支持自定义线程池线程数量
@@ -12,7 +12,7 @@
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<smartjavaai.version>1.0.20</smartjavaai.version>
|
||||
<smartjavaai.version>1.0.22</smartjavaai.version>
|
||||
<!--如果打包运行,需要替换成你的main-->
|
||||
<exec.mainClass>smartai.examples.ocr.common.OcrRecognizeDemo</exec.mainClass>
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import cn.smartjavaai.ocr.entity.OcrInfo;
|
||||
import cn.smartjavaai.ocr.enums.CommonDetModelEnum;
|
||||
import cn.smartjavaai.ocr.factory.OcrModelFactory;
|
||||
import cn.smartjavaai.ocr.model.common.detect.OcrCommonDetModel;
|
||||
import cn.smartjavaai.ocr.opencv.OcrOpenCVUtils;
|
||||
import cn.smartjavaai.ocr.utils.OcrUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -60,7 +59,8 @@ public class OcrDetectionDemo {
|
||||
*/
|
||||
@Test
|
||||
public void detect(){
|
||||
try (OcrCommonDetModel model = getDetectionModel()){
|
||||
try {
|
||||
OcrCommonDetModel model = getDetectionModel();
|
||||
List<OcrBox> boxes = model.detect("src/main/resources/ocr_1.jpg");
|
||||
log.info("OCR检测结果:{}", JSONObject.toJSONString(boxes));
|
||||
} catch (Exception e) {
|
||||
@@ -77,7 +77,8 @@ public class OcrDetectionDemo {
|
||||
*/
|
||||
@Test
|
||||
public void detectAndDraw(){
|
||||
try (OcrCommonDetModel model = getDetectionModel()){
|
||||
try {
|
||||
OcrCommonDetModel model = getDetectionModel();
|
||||
model.detectAndDraw("src/main/resources/ocr_1.jpg", "output/ocr_1_detected.jpg");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -94,7 +95,8 @@ public class OcrDetectionDemo {
|
||||
*/
|
||||
@Test
|
||||
public void batchDetect(){
|
||||
try (OcrCommonDetModel model = getDetectionModel()){
|
||||
try {
|
||||
OcrCommonDetModel model = getDetectionModel();
|
||||
//批量检测要求图片宽高一致
|
||||
String folderPath = "/Users/xxx/Downloads/testing33";
|
||||
//读取文件夹中所有图片
|
||||
|
||||
@@ -67,7 +67,8 @@ public class OcrDirectionDetDemo {
|
||||
*/
|
||||
@Test
|
||||
public void detect(){
|
||||
try (OcrDirectionModel directionModel = getDirectionModel()){
|
||||
try {
|
||||
OcrDirectionModel directionModel = getDirectionModel();
|
||||
List<OcrItem> itemList = directionModel.detect("src/main/resources/ocr_1.jpg");
|
||||
log.info("OCR方向检测结果1:{}", JSONObject.toJSONString(itemList));
|
||||
} catch (Exception e) {
|
||||
@@ -84,7 +85,8 @@ public class OcrDirectionDetDemo {
|
||||
*/
|
||||
@Test
|
||||
public void detectAndDraw(){
|
||||
try (OcrDirectionModel directionModel = getDirectionModel()){
|
||||
try {
|
||||
OcrDirectionModel directionModel = getDirectionModel();
|
||||
directionModel.detectAndDraw("src/main/resources/ocr_3.jpg", "output/ocr_3_detected.png");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -106,7 +106,8 @@ public class OcrRecognizeDemo {
|
||||
*/
|
||||
@Test
|
||||
public void recognize(){
|
||||
try (OcrCommonRecModel recModel = getRecModel()){
|
||||
try {
|
||||
OcrCommonRecModel recModel = getRecModel();
|
||||
//不带方向矫正,分行返回文本
|
||||
OcrRecOptions options = new OcrRecOptions(false, true);
|
||||
OcrInfo ocrInfo = recModel.recognize("src/main/resources/ocr_2.jpg",options);
|
||||
@@ -127,7 +128,8 @@ public class OcrRecognizeDemo {
|
||||
*/
|
||||
@Test
|
||||
public void recognizeHandWriting(){
|
||||
try (OcrCommonRecModel recModel = getRecModel()){
|
||||
try {
|
||||
OcrCommonRecModel recModel = getRecModel();
|
||||
OcrInfo ocrInfo = recModel.recognize("src/main/resources/handwriting_1.jpg",new OcrRecOptions());
|
||||
log.info("OCR识别结果:{}", JSONObject.toJSONString(ocrInfo));
|
||||
} catch (Exception e) {
|
||||
@@ -146,7 +148,8 @@ public class OcrRecognizeDemo {
|
||||
*/
|
||||
@Test
|
||||
public void recognize2(){
|
||||
try (OcrCommonRecModel recModel = getRecModelWithDirection()){
|
||||
try {
|
||||
OcrCommonRecModel recModel = getRecModelWithDirection();
|
||||
//带方向矫正,分行返回文本
|
||||
OcrRecOptions options = new OcrRecOptions(true, true);
|
||||
OcrInfo ocrInfo = recModel.recognize("src/main/resources/ocr_3.jpg",options);
|
||||
@@ -168,7 +171,8 @@ public class OcrRecognizeDemo {
|
||||
*/
|
||||
@Test
|
||||
public void recognizeAndDraw(){
|
||||
try (OcrCommonRecModel recModel = getRecModelWithDirection()){
|
||||
try {
|
||||
OcrCommonRecModel recModel = getRecModelWithDirection();
|
||||
int fontSize = 18;
|
||||
recModel.recognizeAndDraw("src/main/resources/general_ocr_002.png", "output/ocr_4_recognized.jpg", fontSize, new OcrRecOptions());
|
||||
} catch (Exception e) {
|
||||
@@ -184,7 +188,8 @@ public class OcrRecognizeDemo {
|
||||
*/
|
||||
@Test
|
||||
public void batchRecognize(){
|
||||
try (OcrCommonRecModel recModel = getRecModelWithDirection()){
|
||||
try {
|
||||
OcrCommonRecModel recModel = getRecModelWithDirection();
|
||||
//批量检测要求图片宽高一致
|
||||
String folderPath = "/Users/xxx/Downloads/testing33";
|
||||
//读取文件夹中所有图片
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package smartai.examples.ocr.plate;
|
||||
|
||||
import ai.djl.util.JsonUtils;
|
||||
import cn.smartjavaai.common.entity.R;
|
||||
import cn.smartjavaai.common.enums.DeviceEnum;
|
||||
import cn.smartjavaai.common.utils.ImageUtils;
|
||||
import cn.smartjavaai.ocr.config.PlateDetModelConfig;
|
||||
import cn.smartjavaai.ocr.config.PlateRecModelConfig;
|
||||
import cn.smartjavaai.ocr.entity.PlateInfo;
|
||||
import cn.smartjavaai.ocr.enums.PlateDetModelEnum;
|
||||
import cn.smartjavaai.ocr.enums.PlateRecModelEnum;
|
||||
import cn.smartjavaai.ocr.factory.PlateModelFactory;
|
||||
import cn.smartjavaai.ocr.model.plate.PlateDetModel;
|
||||
import cn.smartjavaai.ocr.model.plate.PlateRecModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author dwj
|
||||
*/
|
||||
@Slf4j
|
||||
public class PlateRecDemo {
|
||||
|
||||
//设备类型
|
||||
public static DeviceEnum device = DeviceEnum.CPU;
|
||||
|
||||
/**
|
||||
* 获取车牌检测模型
|
||||
* @return
|
||||
*/
|
||||
public PlateDetModel getPlateDetModel() {
|
||||
PlateDetModelConfig config = new PlateDetModelConfig();
|
||||
config.setModelEnum(PlateDetModelEnum.YOLOV5);
|
||||
config.setModelPath("/Users/wenjie/Downloads/modelscope-2b3747db53adb48370c6edaccac56eb1ca0da1b5/onnx_export/model.onnx");
|
||||
// config.setModelPath("/Users/wenjie/Documents/develop/model/plate/yolov8s.onnx");
|
||||
config.setModelPath("/Users/wenjie/Downloads/数据集/车牌/onnx/plate_detect.onnx");
|
||||
config.setPredictorPoolSize(3);
|
||||
config.setDevice(device);
|
||||
return PlateModelFactory.getInstance().getDetModel(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车牌识别模型
|
||||
* @return
|
||||
*/
|
||||
public PlateRecModel getPlateRecModel() {
|
||||
PlateRecModelConfig recModelConfig = new PlateRecModelConfig();
|
||||
recModelConfig.setModelEnum(PlateRecModelEnum.PLATE_REC_CRNN);
|
||||
recModelConfig.setModelPath("/Users/wenjie/Downloads/数据集/车牌/onnx/plate_rec_color.onnx");
|
||||
recModelConfig.setPlateDetModel(getPlateDetModel());
|
||||
return PlateModelFactory.getInstance().getRecModel(recModelConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetect() {
|
||||
PlateRecModel plateRecModel = getPlateRecModel();
|
||||
R<List<PlateInfo>> result = plateRecModel.recognize("src/main/resources/plate/Quicker_20220930_180856.png");
|
||||
if(result.isSuccess()){
|
||||
log.info("车牌识别结果:{}", JsonUtils.toJson(result.getData()));
|
||||
}else{
|
||||
log.error("车牌识别失败:{}", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recognizeAndDraw() {
|
||||
PlateRecModel plateRecModel = getPlateRecModel();
|
||||
R<Void> result = plateRecModel.recognizeAndDraw("src/main/resources/plate/single_green.jpg", "output/plate_recognized2.jpg");
|
||||
if(result.isSuccess()){
|
||||
log.info("车牌识别成功");
|
||||
}else{
|
||||
log.error("车牌识别失败:{}", result.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -113,10 +113,11 @@ public class TableRecDemo {
|
||||
*/
|
||||
@Test
|
||||
public void recognize(){
|
||||
try (TableStructureModel tableStructureModel = getTableStructureModel();
|
||||
OcrCommonDetModel detModel = getDetectionModel();
|
||||
OcrCommonRecModel recModel = getRecModel();
|
||||
OcrDirectionModel directionModel = getDirectionModel()){
|
||||
try {
|
||||
TableStructureModel tableStructureModel = getTableStructureModel();
|
||||
OcrCommonDetModel detModel = getDetectionModel();
|
||||
OcrCommonRecModel recModel = getRecModel();
|
||||
OcrDirectionModel directionModel = getDirectionModel();
|
||||
//创建表格识别器
|
||||
TableRecognizer tableRecognizer = TableRecognizer.builder()
|
||||
.withStructureModel(tableStructureModel)
|
||||
|
||||
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 1.0 MiB |
|
After Width: | Height: | Size: 241 KiB |
|
After Width: | Height: | Size: 328 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/double_yellow.jpg
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/hongkang1.jpg
Normal file
|
After Width: | Height: | Size: 571 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/moto.png
Normal file
|
After Width: | Height: | Size: 400 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/police.jpg
Normal file
|
After Width: | Height: | Size: 382 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/shi_lin_guan.jpg
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/single_blue.jpg
Normal file
|
After Width: | Height: | Size: 1.8 MiB |
BIN
examples/ocr-examples/src/main/resources/plate/single_green.jpg
Normal file
|
After Width: | Height: | Size: 903 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/single_yellow.jpg
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/tmp8F1F.png
Normal file
|
After Width: | Height: | Size: 932 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/tmpA5E3.png
Normal file
|
After Width: | Height: | Size: 513 KiB |
BIN
examples/ocr-examples/src/main/resources/plate/xue.jpg
Normal file
|
After Width: | Height: | Size: 999 KiB |
BIN
examples/ocr-examples/src/main/resources/table/medal_table.png
Normal file
|
After Width: | Height: | Size: 943 KiB |
BIN
examples/ocr-examples/src/main/resources/table/table_ch1.png
Normal file
|
After Width: | Height: | Size: 219 KiB |