ocr problem for reading numbers

2 次查看(过去 30 天)
Abhishek Kashyap
Abhishek Kashyap 2018-9-9
回答: Sourabh 2025-3-27
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.

回答(1 个)

Sourabh
Sourabh 2025-3-27
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!

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by