Laimonas Sutkus
Laimonas Sutkus

Reputation: 3607

Blurry text from identification documents detection and ocr

I have a very specific scene text detection and parsing problem. I am not even sure if you can say it is an actual scene text.

I have extracted a name field from an identity card photo: enter image description here

I could immediately start applying some OCR on that image, but i believe a further text localisation could be applied. To achieve this image:enter image description here Do you know any of such text localisation algorithms? I have already tried 'FASText by Busta', 'EAST by argman' and they work decently. Any algorithms on this specific task?

After the localisation of the text i think now it is the best time to apply OCR. And now i feel lost. Which OCR could you recommend to use? I have already tried 'Tesseract' but it just doesn't work well. Is it a better idea to make your own OCR for document characters by using e.g. Tensorflow?

Upvotes: 1

Views: 2860

Answers (1)

nsidn98
nsidn98

Reputation: 1087

Try to increase the contrast of the image. You can use:

import matplotlib.pyplot as plt
import cv2
import numpy as np


def cvt_BGR2RGB(img):
  return cv2.cvtColor(img,cv2.COLOR_BGR2RGB)


def contrast(img,show=False):
  # CLAHE (Contrast Limited Adaptive Histogram Equalization)
  clahe=cv2.createCLAHE(clipLimit=3., tileGridSize=(8,8))

  lab=cv2.cvtColor(img, cv2.COLOR_BGR2LAB)  # convert from BGR to LAB color space
  l,a,b=cv2.split(lab)  # split on 3 different channels

  l2=clahe.apply(l)  # apply CLAHE to the L-channel

  lab=cv2.merge((l2,a,b))  # merge channels
  img2=cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)  # convert from LAB to BGR
  if show:
    #plot the original and contrasted image
    f=plt.figure(figsize=(15,15))
    ax1=f.add_subplot(121)
    img1_cvt=cvt_BGR2RGB(img)
    plt.imshow(img1_cvt)
    ax2=f.add_subplot(122)
    img2_cvt=cvt_BGR2RGB(img2)
    plt.imshow(img2_cvt)
    plt.show()
  return img,img2

And maybe then you can use pyteserract

Upvotes: 1

Related Questions