如何删除从图像中提取的不需要的文本?

How to remove unwanted text extracted from the image?

我正在做一个名为 Business Card Scanner 的项目。我正在使用 pytesseract 从图像中提取文本,然后使用正则表达式和其他技术对获得的文本进行分类。

只要图像中有徽标,tesseract 就会将其视为文本并尝试读取它。这导致无意义的文本。考虑下面的图片示例:

IMG

这是我试图提取的文本:

# Google colab
# read required libraries
img = cv2.imread("img2.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5,5),0)
ret3, thresh = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2_imshow(thresh)
text = pytesseract.image_to_string(thresh, lang = 'eng'); print(text)

这是我 运行 上述代码时得到的输出:

: eM , NOEs Efe: Mb fes fe y Ky TEP ON PILLS cag
gy: Ye Ws My Wii WL, FLY T by,

i igs Mg ER te EB iy MY, Gee.
: WO Ee as _ he i. "4 ‘; y sen “iy ye age i ‘ el HY tiber My, ee ered fi! ", ty Mf

Mm Gujarat TE og
: , fp bet
(x = Technological ( Wy, ey,

sae ae e . Tf) :
wage University ~~ es

e e é et

ikhil Suthar lees
fy Lg. Z - “fe " ‘Sa
. ve 7, of

Regional Coordinator - OSD MWe) Dh
ye

Mob. <hidden>

Email : <hidden>

Govt. Technical High School Campus, Near Aurobindo
Ashram Dandia Bazar,Vadodara - 390001, Gujarat, India
www.gtu.ac.in | www-gtuinnovationcouncil.2¢.in

i Ae

; ew, OD
t eS ft me ' @
ate
ary ya
j my

ee |
a

有什么方法可以删除由于徽标而产生的不需要的文本(我就是这么想的)?如果我的问题需要其他信息,请告诉我。

图片的背景有问题。您可以通过 selecting a height-range

来省略

例如:如果您 select 高度范围介于:h/4 - (3*h)/4,结果将是:(由于超过 2MiB,图像被调整大小。)

当您阅读时:

Nikhil Suthar
Regional Coordinator - OSD

Email | Mob. |

Govt. Technical High School Campus, Near Aurobindo
Ashram Dandia Bazar, Vadodara - 390001, Gujarat, India
www.gtu.ac.in | www.gtuinnovationcouncil.ac.in

代码:


import cv2
from pytesseract import image_to_string

img = cv2.imread("Oa9svHu.jpeg")
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
(h, w) = gry.shape[:2]
gry = gry[int(h/4):int((3*h)/4), 0:w]
txt = image_to_string(gry)
print(txt.strip())
cv2.imshow("gry", gry)
cv2.waitKey(0)