This commit is contained in:
2026-08-07 17:46:23 +08:00
parent 98ac9840c2
commit 645c483649
22 changed files with 370 additions and 29 deletions
@@ -1,16 +1,22 @@
package com.baiyue.integration.dto.ocr;
import java.math.BigDecimal;
/**
* 百度 OCR 返回的文字候选及其识别框。
*/
public record OcrCandidate(
String text,
Double confidence,
BigDecimal confidence,
Integer left,
Integer top,
Integer width,
Integer height
) {
public OcrCandidate {
confidence = OcrConfidence.normalize(confidence);
}
public long area() {
if (width == null || height == null || width <= 0 || height <= 0) {
return 0;
@@ -0,0 +1,27 @@
package com.baiyue.integration.dto.ocr;
import java.math.BigDecimal;
import java.math.RoundingMode;
/** Canonical confidence representation shared by OCR response models. */
public final class OcrConfidence {
private static final int SCALE = 5;
private static final BigDecimal ZERO = BigDecimal.ZERO.setScale(SCALE);
private static final BigDecimal ONE = BigDecimal.ONE.setScale(SCALE);
private OcrConfidence() {
}
public static BigDecimal normalize(BigDecimal value) {
if (value == null) {
return null;
}
if (value.compareTo(BigDecimal.ZERO) < 0) {
return ZERO;
}
if (value.compareTo(BigDecimal.ONE) > 0) {
return ONE;
}
return value.setScale(SCALE, RoundingMode.HALF_UP);
}
}
@@ -12,10 +12,15 @@ public record WeightOcrImageResult(
String rawResponseFile,
Status status,
BigDecimal weight,
Double confidence,
BigDecimal confidence,
List<OcrCandidate> candidates,
String ocrRawText,
String error
) {
public WeightOcrImageResult {
confidence = OcrConfidence.normalize(confidence);
}
public enum Status {
RECOGNIZED,
NO_WEIGHT_FOUND,