我们正在使用 tesseract 进行 pan OCR,但无法检测到名称和 pan 编号等详细信息

we are doing pan OCR, using tesseract but is not able to detect the details like name and pan number

我们通过每次迭代将高度增加 20px 来裁剪 pan card 图像,然后我们将该图像传递给 tesseract 以进行 ocr,但是我们得到了噪音output.if 你有更好的图像解决方案处理或 另一个像 cv2 这样的库请帮助我们。

import pytesseract
from PIL import Image, ImageEnhance, ImageFilter

im = Image.open("image/testpan.jpg")
width = im.size[0]
height = im.size[1]
print('width,height-->',width,height)

yy='img'
zz='.jpg'

x=0
for j in range(x,height):
    img2 = im.crop((0, x, width/2,x+70))
    img2.save(yy+str(j)+zz)

    img = Image.open(yy+str(j)+zz)
    # img = img.convert("L")
    img.save(yy + str(j) + zz)
    text = pytesseract.image_to_string(Image.open(yy+str(j)+zz))
    print('IIIII',j, text)

    x=x+20
    j=x
    if j>height:
        break

这样可以吗?

  1. 转换为灰色
  2. threshold
  3. findContours
  4. boundingRect