ocr problem for reading numbers

2 visualizzazioni (ultimi 30 giorni)
Abhishek Kashyap
Abhishek Kashyap il 9 Set 2018
Risposto: Sourabh il 27 Mar 2025
I am totally unable to read the numbers from the following image. I tried CharacterSet, regionprops, imdialate. but not even one number gets recognized. please help.

Risposte (1)

Sourabh
Sourabh il 27 Mar 2025
I was also unable to extract the numbers when I tried MATLAB’s “ocr” function on the given image. The result was an empty string, and it couldn’t recognize the numbers as expected.
I found that “ocr performs best when the text is located on a uniform background and is formatted like a document with dark text on a light background. When the text appears on a non-uniform dark background, additional pre-processing steps are required to get the best OCR results.
To overcome the challenges obtaining accurate results, kindly follow the preprocessing steps given below:
  • Convert to Grayscale
OCR performs better on grayscale images than on RGB images
grayImage = rgb2gray(rgbImage);
  • Sharpen the Image
To enhance the edges of the text and make it more readable for OCR:
sharpenedImage = imsharpen(grayImage);
  • Noise Reduction
Use a median filter or Gaussian filter to smooth the image while preserving edges:
filteredImage = medfilt2(grayImage, [3 3]); % Median filter
  • Binarization (Thresholding)
Convert the grayscale image to a binary image using Otsu's method
binaryImage = imbinarize(filteredImage);
  • Text Stroke Width Normalization
If text has varying thickness, normalize it using the Stroke Width Transform (SWT):
binaryImage = bwareafilt(binaryImage, [30, Inf]); % Keep only large connected components
  • Morphological Operations
Remove small noise and connect broken characters using dilation and erosion:
se = strel('disk', 1);
erodeImage = imerode(binaryImage, se);
You can also set “LayoutAnalysis to "Block" to instruct ocr to assume the image contains just one block of text.
results = ocr(binaryImage,LayoutAnalysis="Block");
results.Text
For more information, please refer to the following MATLAB documentation:
I hope this helps!

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by