Replies: 2 comments 1 reply
-
To make PaddleOCR return single words instead of word groups, you can modify the way you process the OCR output. By default, PaddleOCR detects and returns text groups consisting of multiple words in a single bounding box. To extract single words, you need to split detected text into individual words manually. Solution:Modify your code so that it processes each detected text block and splits them into individual words. Updated Code:from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
# Initialize OCR
ocr = PaddleOCR(use_angle_cls=True, lang='en')
# Image path
img_path = r'C:\Users\UserA\image.jpg'
# Run OCR
result = ocr.ocr(img_path, cls=True)
# Process results
for idx in range(len(result)):
res = result[idx]
for line in res:
bbox, (text, score) = line # Bounding box and recognized text
words = text.split() # Split text into individual words
for word in words:
print(f"Word: {word}, Confidence: {score}")
# Visualization
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result[0]] # Extract bounding boxes
txts = [word for line in result[0] for word in line[1][0].split()] # Extract individual words
scores = [line[1][1] for line in result[0]] # Extract confidence scores
# Draw OCR result
im_show = draw_ocr(image, boxes, txts, scores, font_path='C:/Users/UserA/PaddleOCR-2.10.0/doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg') Explanation:
Alternative Approach:If you need precise word-level bounding boxes, you might need to modify the OCR model or explore a character-level or word-level detection approach. A related discussion on how to get single characters and coordinates is available here: Would you like more details on fine-tuning the model to enhance word-level detection? 😊 Response generated by 🤖 feifei-bot | chatgpt-4o-latest |
Beta Was this translation helpful? Give feedback.
-
please refer to https://paddlepaddle.github.io/PaddleOCR/latest/en/ppstructure/blog/return_word_pos.html |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working with the example but can't figure out how to get single words instead of word groups.
Beta Was this translation helpful? Give feedback.
All reactions