-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyCode.py
48 lines (25 loc) · 1017 Bytes
/
MyCode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# OCR of E-aadhar cards [Good quality images]
#Image quality enhancement – Improve the quality of the images using image processing libraries
# First import the librares
import cv2
import pytesseract
import numpy as np
"""Convert the image into black and white"""
#read image
img_grey = cv2.imread("CARD.jpg", cv2.IMREAD_GRAYSCALE)
# define a threshold, 128 is the middle of black and white in grey scale
thresh = 128
# threshold the image
img_binary = cv2.threshold(img_grey, thresh, 255, cv2.THRESH_BINARY)[1]
#save image
cv2.imwrite("CARD2.jpg",img_binary)
"""Now Noise Removal & Image Sharpening"""
bW = cv2.imread("CARD2.jpg")
bi_blur = cv2.bilateralFilter(bW, 9, 75, 75)
cv2.imwrite("CARD3.jpg",bi_blur)
final = cv2.imread("CARD3.jpg")
print(final.shape)
# Recognise the digits
custom_config = r'--oem 3 --psm 6 outputbase digits'
# Printing the details of the aadhar card
print(pytesseract.image_to_string(final, config=custom_config))