- This topic has 1 reply, 2 voices, and was last updated 4 years, 8 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
Home › Forums › Fórum Reconhecimento de Textos com OCR e Python › Tesseract – Reconhece o “conf” – confiabilidade como se fosse uma string
Tagged: Detecção em cenários naturais
import pytesseract
import cv2
from pytesseract import Output
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
img = cv2.imread(r"C:\Users\Documents\Python\OCR\Programa\teste_manuscrito_01.jpg")
rgb = cv2.cvtColor (img, cv2.COLOR_BGR2RGB)
resultado = pytesseract.image_to_data(rgb, lang='por', output_type=Output.DICT)
print(resultado)
{'level': [1, 2, 3, 4, 5, 4, 5, 5],
'page_num': [1, 1, 1, 1, 1, 1, 1, 1],
'block_num': [0, 1, 1, 1, 1, 1, 1, 1],
'par_num': [0, 0, 1, 1, 1, 1, 1, 1],
'line_num': [0, 0, 0, 1, 1, 2, 2, 2],
'word_num': [0, 0, 0, 0, 1, 0, 1, 2],
'left': [0, 38, 38, 38, 38, 102, 102, 307],
'top': [0, 79, 79, 79, 79, 228, 233, 228],
'width': [700, 607, 607, 607, 607, 532, 77, 327],
'height': [400, 236, 236, 92, 92, 87, 76, 87],
'conf': ['-1', '-1', '-1', '-1', '90.214363', '-1', '77.749153', '61.677670'],
'text': ['', '', '', '', 'TESTANDO', '', 'O', 'OCR...']}
consequentemente da erro em seguida:
confianca = int(resultado[‘conf’] [i])
ValueError: invalid literal for int() with base 10: ‘90.214363’
Como faço para o tesseract reconhecer o ‘CONF’ como INT ?
OBrigado
Olá Bruno!
Nesse caso creio que terá que converter para valor de ponto flutuante antes de passar pro int(), ou seja, usar a função float() antes.
Então ficaria assim: confianca = int(float(resultado[‘conf’] [i]))
Se o erro persistir avise!