mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-14 05:38:50 +00:00
本地修改
This commit is contained in:
@@ -28,20 +28,6 @@ public class PlateRecModelConfig extends ModelConfig {
|
||||
*/
|
||||
private PlateDetModel plateDetModel;
|
||||
|
||||
/**
|
||||
* 置信度阈值
|
||||
*/
|
||||
private float confidenceThreshold;
|
||||
|
||||
/**
|
||||
* iou阈值
|
||||
*/
|
||||
private float iouThreshold;
|
||||
|
||||
/**
|
||||
* 检测结果数量
|
||||
*/
|
||||
private int topK;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -286,18 +286,8 @@ public class OcrCommonRecModelImpl implements OcrCommonRecModel {
|
||||
if(Objects.isNull(ocrInfo) || Objects.isNull(ocrInfo.getLineList()) || ocrInfo.getLineList().isEmpty()){
|
||||
throw new OcrException("未检测到文字");
|
||||
}
|
||||
try {
|
||||
OcrUtils.drawRectWithText(sourceImage, ocrInfo, fontSize);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
// 调用 save 方法将 Image 写入字节流
|
||||
img.save(outputStream, "png");
|
||||
// 将字节流转换为 BufferedImage
|
||||
byte[] imageBytes = outputStream.toByteArray();
|
||||
((Mat) img.getWrappedImage()).release();
|
||||
return ImageIO.read(new ByteArrayInputStream(imageBytes));
|
||||
} catch (IOException e) {
|
||||
throw new OcrException("导出图片失败", e);
|
||||
}
|
||||
OcrUtils.drawRectWithText(sourceImage, ocrInfo, fontSize);
|
||||
return sourceImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@ import cn.smartjavaai.common.utils.LetterBoxUtils;
|
||||
import cn.smartjavaai.common.utils.NMSUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -92,6 +93,11 @@ public class Yolo5PlateDetectTranslator implements Translator<Image, DetectedObj
|
||||
// 联合过滤
|
||||
NDArray jointMask = jointScore.gt(confThreshold);
|
||||
detsFiltered = detsFiltered.get(jointMask);
|
||||
|
||||
if (detsFiltered.isEmpty()) {
|
||||
return new DetectedObjects(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
||||
}
|
||||
|
||||
clsLogits = clsLogits.get(jointMask);
|
||||
|
||||
|
||||
@@ -113,7 +119,10 @@ public class Yolo5PlateDetectTranslator implements Translator<Image, DetectedObj
|
||||
NDArray output = NDArrays.concat(new NDList(boxes, scores, keyPoints, indices), 1); // (N, 14)
|
||||
|
||||
// NMS 过滤掉重叠框
|
||||
int[] keepIndices = NMSUtils.nms(boxes, scores.squeeze(), iouThreshold); // scores.squeeze() ➝ (N,)
|
||||
int[] keepIndices = NMSUtils.nms(boxes, scores.squeeze(), iouThreshold); // scores.squeeze() ➝ (N,)】
|
||||
if (keepIndices.length == 0) {
|
||||
return new DetectedObjects(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
||||
}
|
||||
NDArray kept = output.get(manager.create(keepIndices));
|
||||
// 如果超过 topK,则截断
|
||||
if (keepIndices.length > topK) {
|
||||
|
||||
Reference in New Issue
Block a user