- Как настроить EasyOCR так, чтобы он распознавал только слова, не разбивая их на несколько блоков?
- У меня есть основная информация в виде текстовых файлов. Как я могу оценить обнаруженные слова и сравнить их с истинными?
import easyocr
import cv2
import matplotlib.pyplot as plt
import numpy as np
# Initialize reader
reader = easyocr.Reader(['en']) # Specify languages
# Read image
image_path = 'C:\\Users\\shiek\\Downloads\\Python_codes_PhD\\Dataset\\Integrated\\selfMade_100.png'
image = cv2.imread(image_path)
ret, image = cv2.threshold(image, 127, 255, cv2.THRESH_TOZERO)
# Force word-level detection instead of text block detection
results = reader.readtext(
image,
decoder = 'greedy',
beamWidth=10,
width_ths=0.1, # Very small - forces separation
height_ths=0.1, # Very small
ycenter_ths=0.1, # Very small
min_size=5, # Minimum pixel size of text
text_threshold=0.5, # Adjust text confidence
low_text=0.3, # Lower threshold for weak text
link_threshold=0.4, # Lower = more separation
mag_ratio=1.0, # No magnification
detail = 1,
adjust_contrast = 0.5
)
# Display results
for (bbox, text, prob) in results:
print(f"Text: {text}, Confidence: {prob:.4f}")
print(f"Bounding Box: {bbox}")
# Draw bounding box
top_left = tuple(map(int, bbox[0]))
bottom_right = tuple(map(int, bbox[2]))
cv2.rectangle(image, top_left, bottom_right, (0, 255, 0), 1)#2
cv2.putText(image, text, top_left, cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 1)#2
plt.imshow(image)
plt.show()
Мобильная версия