【问题标题】:Does PyTesseract OCR give the confidence of the text detection or text extraction?PyTesseract OCR 是否提供了文本检测或文本提取的置信度?
【发布时间】:2021-03-12 05:31:59
【问题描述】:

当 Pytesseract 与命令 pytessract.image_to_data 一起使用时,它会返回许多值,其中之一是置信度。这种自信意味着什么?是文本检测的置信度,即文本是否存在?

还是提取的实际文本的置信度? 如果有人也可以指出我找到这个问题的答案的来源,将非常感激。

【问题讨论】:

    标签: python-3.x ocr python-tesseract


    【解决方案1】:
    • 这种信心意味着什么?是文本检测的置信度,即文本是否存在?还是提取的实际文本的置信度?

    表示当前文本在边界框中的预测准确度。可以肯定地说提取的实际文本的置信度。正如here 中所述,您可以使用它来过滤弱检测。

    那么我们如何在示例中使用它呢?

    假设我们有以下示例:

    我们希望以大于 40% 的置信度识别文本。

    结果将是:

    如果我们查看边界框:

    Detected Result Confidence
    ESTATE 96
    AGENTS 96
    =! 48

    我们可以看到 SAXONS 无法识别。信心也是pre-processing效率的一个很好的指标。

    例如,如果我们申请adaptive-threshold

    Detected Result Confidence
    ESTATE 51
    AGENTS 69
    SAXONS 42

    从上面我们可以看出,所有的文本都被识别出来了,但是之前识别出来的文本置信度比现在要大。

    结果将是:

    代码:


    # Load the libraries
    import cv2
    import pytesseract
    
    # Load the image
    img = cv2.imread("example_03.jpg")
    
    # Convert it to the gray-scale
    gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
    # threshold
    thr = cv2.adaptiveThreshold(gry, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 71, 71)
    
    # OCR detection
    d = pytesseract.image_to_data(thr, config="--psm 6", output_type=pytesseract.Output.DICT)
    
    # Get ROI part from the detection
    n_boxes = len(d['text'])
    
    # For each detected part
    for i in range(n_boxes):
    
        # If the prediction accuracy greater than %50
        if int(d['conf'][i]) > 40:
    
            # Print the confidence
            print("\nConfidence: {}\n".format(d['conf'][i]))
    
            # Get the localized region
            (x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
    
            # Draw rectangle to the detected region
            cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 5)
    
            # Crop the image
            crp = thr[y:y + h, x:x + w]
    
            # OCR
            txt = pytesseract.image_to_string(crp, config="--psm 6")
            print(txt)
    
            # Display the cropped
            cv2.imshow("crp", crp)
            cv2.waitKey(0)
    
    # Display the mask
    cv2.imshow("img", img)
    cv2.waitKey(0)
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多