1
$\begingroup$

I'm performing some rudimentary OCR on some images that I have. The image below is from a VIN tag in a car. The image was originally color with a lot of glare that made some of the characters illegible. I performed the following operations.

  • Color Invert (tag was black and text was white, I wanted the reverse)
  • Color Threshold to get rid of the worst of the glare.
  • Make image black+white only
  • Erode/Dilate in order to tinker with the text to make it easier for Tesseract OCR to read.
  • Run Tesseract OCR to extract the characters

The issue that I'm having now is that the black "fuzz" that surrounds the sticker is slowing down Tesseract. What I would like is the name of some operation or a series of steps that I can regularly use in a case like this to get rid of these distortions. I could manually write something to look at squares of the image and if there's way more dark then light, replace with white. There has to be some formal image processing technique to handle this case that I just don't know of.

If I manually remove the black in the margins, my accuracy goes up substantially in Tesseract.

VIN Tag

$\endgroup$
1
  • $\begingroup$ Use edges to find the bright white area, and run tesseract only on that ? And lay of the erose/dilate unless you are really plagued by pixel noise. It will deform the letters. $\endgroup$
    – Marco van de Voort
    Commented Nov 11, 2016 at 21:27

1 Answer 1

1
$\begingroup$

You can perform local averaging/blurring of the picture and then use a threshold to remove all areas that are too dark:

img = cv2.imread('k1aqp.png')
figure(figsize=(20,20))
subplot(2,2,1);
imshow(img)

subplot(2,2,2);
B = cv2.blur(img, (55,55), 0)
imshow(B)

subplot(2,2,3)
mask = B > 150
imshow(mask)

subplot(2,2,4)
img2 = img.copy()
img2[~mask] = 255
imshow(img2)

program output

you need to play around with the blur size and the threshold. But in general, this is one way to go.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.