Необходимо удалить строки из изображений типа приложения - PullRequest
0 голосов
/ 25 февраля 2020

Мне нужно извлечь данные из формы заявки. Я удалил горизонтальные и вертикальные линии на изображении ниже, но нижняя часть текста удалена и я не могу четко извлечь данные.

enter image description here

Здесь мой код

import cv2
import numpy as np

image = cv2.imread('kumarD_1.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Remove horizontal
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25, 1))
detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
cnts = cv2.findContours(detected_lines, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(image, [c], -1, (255, 255, 255), 2)

# Remove vertical
vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 20))
detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, vertical_kernel, iterations=2)
cnts = cv2.findContours(detected_lines, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(image, [c], -1, (255, 255, 255), 2)

# Repair image
repair_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,6)
result = 255 - cv2.morphologyEx(255 - image, cv2.MORPH_CLOSE, repair_kernel, iterations=1)

import pytesseract
img = cv2.imread("linesremoved.jpg")
print(pytesseract.image_to_string(img))

И я получаю вывод, подобный этому ...

reose sect tite, [Blox opptioble
(ena
sent
Lastname/surame MOONDRA
First Name USHA
Middle Name
ee Oe oa | |
ASSP NE
Last Name / Surnarne
First Name
Middle Name
tae
tonth
iz)
ee oe a i
Name of office jw ula one
ef FL
Flat/Roornf oor / Block No. 02220 aaa TN TES
Name of Premisesf Bullding/ Village ISIHIRITIPIAIL] INIAIGIAIRI Tt ttt bit bid
Road/Street/ Lane/Post Office ISIAIKIEIT] IAISIHIRIAIM] [RIOIAIDI | 1 1 ttt dl
Area f Locality / Talukaf Sub- Division (STU IMIEIRI EIU Sa
Town {City / District FAC 1 EL | a Na
State f Union Territory Pincode f Zip code Country Name
I RAJASTHAN 13fol6l9lol2t | INDIA |
Telephone / Mobile number
1911161614111713 11 171
Country code Area/STO Code
I 1 1 10121913131
I
INFO@ETDSDSC.COM |
emaitio |
aL |
uwe | USHA MIDONDAA
the applicant, inthe capactyot | TNPIVIDVYAL |
do hereby declare that what is stated above is true to the best of my/our information and belief.
fe have enclosed
oOoMM
| SUMER PUR. |
Y
[2i2|ol4iziolr I
(number of documents) in support of proposed changes/corrections.
Yea Moondra
Signature / Left Thumb Impression of Applicant
{inside the box)
YY
MSTPLPC1203

Пожалуйста, помогите мне в этом .. Я не могу четко извлечь рукописные тексты.

...