Skip to content

ROI 越界:内部OcrUtils.transformAndCrop(srcMat, box)异常 #36

Description

@cccchiu666

透视变换 + 裁剪
cn.smartjavaai.ocr.exception.OcrException: OCR检测错误
at cn.smartjavaai.ocr.model.common.recognize.OcrCommonRecModelImpl.batchRecognizeDJLImage(OcrCommonRecModelImpl.java:458)
at cn.smartjavaai.ocr.model.common.recognize.OcrCommonRecModelImpl.recognize(OcrCommonRecModelImpl.java:128)
at com.ljd.ai.service.OcrModelProvider.recognize(OcrModelProvider.java:81)
at com.ljd.ai.service.impl.OcrRecognizeImpl.recognizeAndSave(OcrRecognizeImpl.java:49)
at com.ljd.task.AsyncTaskConsumer.lambda$consumeOcrTask$1(AsyncTaskConsumer.java:134)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.opencv.core.CvException: cv::Exception: OpenCV(4.9.0) /home/runner/work/opencv/opencv/opencv-4.9.0/modules/core/src/matrix.cpp:808: error: (-215:Assertion failed) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function 'Mat'

at org.opencv.core.Mat.n_submat(Native Method)
at org.opencv.core.Mat.submat(Mat.java:697)
at cn.smartjavaai.common.utils.OpenCVUtils.getSubImage(OpenCVUtils.java:730)
at cn.smartjavaai.ocr.utils.OcrUtils.transformAndCropToMat(OcrUtils.java:210)
at cn.smartjavaai.ocr.utils.OcrUtils.transformAndCrop(OcrUtils.java:176)
at cn.smartjavaai.ocr.model.common.recognize.OcrCommonRecModelImpl.batchAlign(OcrCommonRecModelImpl.java:153)
at cn.smartjavaai.ocr.model.common.recognize.OcrCommonRecModelImpl.batchRecognizeDJLImage(OcrCommonRecModelImpl.java:439)
... 5 common frames omitted

cvMat仍然与原图一样大,如果计算出的 img_crop_width 大于原图宽度,submat 就会越界。
希望可以解决优化

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions