如何使用python刪除最低概率值

我有一個(gè)圖像,我想在其中檢測文本,我使用easyocr檢測文本。OCR給出輸出邊界框值和概率,如輸出圖像所示。我想去掉檢測到的任何文本中小于0.4的概率,我如何改變它?

Image1

Image 2

結(jié)果元素給出了第一個(gè)文本和第二個(gè)文本“AA”的輸出概率,如圖所示。我想刪除檢測到的概率最低的文本。

圖像1的輸出

圖像2的輸出

Requirements

pip安裝pytesseract

pip安裝easyocr

使用pythonmain.py-iimage1.jpg運(yùn)行代碼

# import the necessary packages
from pytesseract import Output
import pytesseract
import argparse
import cv2
from matplotlib import pyplot as plt
import numpy as np
import os
import easyocr
from PIL import ImageDraw, Image



def remove_lines(image):
    result = image.copy()
    gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

    # Remove horizontal lines
    horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (40,1))
    remove_horizontal = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
    cnts = cv2.findContours(remove_horizontal, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if len(cnts) == 2 else cnts[1]
    for c in cnts:
        cv2.drawContours(result, [c], -1, (255,255,255), 5)


    # Remove vertical lines
    vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,40))
    remove_vertical = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, vertical_kernel, iterations=2)
    cnts = cv2.findContours(remove_vertical, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if len(cnts) == 2 else cnts[1]
    for c in cnts:
        cv2.drawContours(result, [c], -1, (255,255,255), 5)

    plt.imshow(result)
    plt.show()

    return result



# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
    help="path to input image to be OCR'd")
ap.add_argument("-c", "--min-conf", type=int, default=0,
    help="mininum confidence value to filter weak text detection")
args = vars(ap.parse_args())


reader = easyocr.Reader(['ch_sim','en']) # need to run only once to load model into memory



# load the input image, convert it from BGR to RGB channel ordering,
# and use Tesseract to localize each area of text in the input image
image = cv2.imread(args["image"])
# image = remove_lines(image)

results = reader.readtext(image)


print(results)

? 最佳回答:
results=[([[5, 0],[233, 0],[233, 15],[5, 15]],' ? ]TC T III3 U?CU 3', 0.011015821004953916),
 ([[241, 0], [390, 0], [390, 15], [241, 15] ] , '?A[ [ C 0l?', 0.0023567583563770737),
 ([[2, 16], [46, 16], [46, 42], [2, 42]], 'MM', 0.9965182566504686),
 ([[98, 16], [140, 16], [140, 46], [98, 46]], 'D', 0.9973547096148511),
 ([[182, 16], [220, 16],[220, 44], [182, 44]], 'Y', 0.9971791823074896),
 ([[24, 46], [62, 46], [62, 74], [24, 74]], '62', 0.9999828941291119),
 ([[94, 46], [130, 46], [130, 74], [94, 74]], '26', 0.9997197349619524),
 ([[180, 46], [242, 46], [242, 74], [180, 74]],'1970', 0.999931275844574)]

low_precision = []
for text in results:
    if text[2]<0.5: # precision here
        low_precision.append(text)
for i in low_precision:
    results.remove(i) # remove low precision
print(results)

result:

[([[2, 16], [46, 16], [46, 42], [2, 42]], 'MM', 0.9965182566504686),
 ([[98, 16], [140, 16], [140, 46], [98, 46]], 'D', 0.9973547096148511),
 ([[182, 16], [220, 16], [220, 44], [182, 44]], 'Y', 0.9971791823074896),
 ([[24, 46], [62, 46], [62, 74], [24, 74]], '62', 0.9999828941291119),
 ([[94, 46], [130, 46], [130, 74], [94, 74]], '26', 0.9997197349619524),
 ([[180, 46], [242, 46], [242, 74], [180, 74]], '1970', 0.999931275844574)]
主站蜘蛛池模板: 无码人妻精品一区二区三区久久| 日韩视频一区二区在线观看| 91精品乱码一区二区三区| 日本视频一区二区三区| 日韩一区二区在线视频| 久久se精品一区精品二区| 亚洲国模精品一区| 在线成人综合色一区| 精品欧美一区二区在线观看| 亚洲国产成人精品无码一区二区| 国产亚洲3p无码一区二区| 日韩精品无码视频一区二区蜜桃| 无码人妻精品一区二区蜜桃AV| 国模无码一区二区三区| 亚洲av无码成人影院一区| 中文字幕一区在线观看视频| 亚洲美女一区二区三区| 久久精品一区二区| 国产剧情国产精品一区| 国产成人久久精品一区二区三区| 日本精品高清一区二区| 国产美女精品一区二区三区| 亚洲色无码一区二区三区| 99久久国产精品免费一区二区| 成人区精品人妻一区二区不卡| 中文字幕AV一区中文字幕天堂| 亚洲中文字幕无码一区二区三区| 亚洲爆乳无码一区二区三区| 无码国产精品一区二区免费3p| 色偷偷久久一区二区三区| 国产精品第一区揄拍| 日本一区二三区好的精华液| 欧美av色香蕉一区二区蜜桃小说| 在线免费视频一区二区| 波多野结衣一区在线| 中文字幕日本精品一区二区三区| 美女福利视频一区| 无码人妻精品一区二区蜜桃 | 久久亚洲国产精品一区二区| 久久亚洲国产精品一区二区| 精品人妻AV一区二区三区|