I am using the Keras OCR library for optical character recognition and I’m encountering an issue with recognizing floating-point numbers, specifically numbers with decimal points. Currently, the OCR model is detecting numbers like “700.25” as “70025”, merging the digits instead of recognizing the decimal point.
Here’s an example of what I’ve tried:
Custom Recognizer:
I have created a custom Recognizer with an adjusted alphabet to include the “.” (dot) character:
Despite this adjustment, the OCR still does not reliably recognize floating-point numbers.
`
import keras_ocr
def detect_and_print_numbers(image_path):
# Create a custom Recognizer with adjusted alphabet to include "."
recognizer = keras_ocr.recognition.Recognizer(alphabet="0123456789.")
# Create the pipeline with the custom Recognizer
pipeline = keras_ocr.pipeline.Pipeline(recognizer=recognizer)
# Recognize text in the image
prediction_groups = pipeline.recognize([image_path])
recognized_numbers = []
# Iterate through predictions and print recognized text
for predictions in prediction_groups:
for prediction in predictions:
text = ''.join(prediction[0]) # Join predicted characters into a string
recognized_numbers.append(text)
return recognized_numbers
Example usage
image_path = '/path/to/your/image.jpg'
recognized_numbers = detect_and_print_numbers(image_path)
# Print recognized numbers
for number in recognized_numbers:
print(f"Recognized Text: {number}")
`
Result is
(‘70025’, array([[…, instead of “700.25
OCR Model Settings:
According to the Keras OCR documentation, there are parameters like text_threshold and link_threshold that can be adjusted to potentially improve the detection of finer details such as decimal points. However, I’m unsure of the exact settings that would optimize the OCR for this specific task.
Question:
How can I adjust the OCR model settings in Keras OCR to ensure accurate detection and recognition of floating-point numbers? Are there specific parameters or techniques that I should focus on tweaking within the Pipeline or Recognizer to achieve this?
Any guidance or examples on adjusting these settings effectively would be greatly appreciated. Thank you!
Jeyhun Sadigov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.