-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcheque_id.py
More file actions
96 lines (79 loc) · 3.15 KB
/
cheque_id.py
File metadata and controls
96 lines (79 loc) · 3.15 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# import the necessary packages
import cv2
from time import sleep
import numpy as np
def call(image):
import cv2
from sklearn.externals import joblib
from skimage.feature import hog
import numpy as np
# Load the classifier
#havent created one yet.
im = image
im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
im_gray = cv2.GaussianBlur(im_gray, (5, 5), 0)
ret, im_th = cv2.threshold(im_gray, 120, 255, cv2.THRESH_BINARY_INV)
cv2.imshow("Resulting Imasdangular ROIs", im_th)
_,ctrs, hier = cv2.findContours(im_th.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
rects = [cv2.boundingRect(ctr) for ctr in ctrs]
for rect in rects:
cv2.rectangle(im, (rect[0], rect[1]), (rect[0] + rect[2], rect[1] + rect[3]), (0, 255, 0), 3)
leng = int(rect[3] * 1.6)
pt1 = int(rect[1] + rect[3] // 2 - leng // 2)
pt2 = int(rect[0] + rect[2] // 2 - leng // 2)
roi = im_th[pt1:pt1+leng, pt2:pt2+leng]
# Resize the image
print(roi.shape[:2])
if(roi.shape[0] > 28 and roi.shape[1] > 28):
roi = cv2.resize(roi, (28, 28), interpolation=cv2.INTER_AREA)
roi = cv2.dilate(roi, (3, 3))
else:
continue;
cv2.putText(im, '', (rect[0], rect[1]),cv2.FONT_HERSHEY_DUPLEX, 0.5, (0, 200, 200), 1)
cv2.imshow("Resulting Image with Rectangular ROIs", im)
img = cv2.imread("image.jpg")
#img = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
#edges = cv2.Canny(img,20,100)
#
#key = cv2.waitKey(1) & 0xFF
#
#
#cv2.imshow('mask',edges)
#cv2.imshow("Frame", frame)
max_brightness = 0
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
canvas = img.copy()
#ret,thresh = cv2.threshold(gray,199,255,1)
blur = cv2.medianBlur(img,5)
edged = cv2.Canny(blur, 25, 70)
zz,contours,h= cv2.findContours(edged,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
#cv2.imshow("asd",zz)
#cv2.drawContours(img, contours,-1, (0,255,0), 3)
for cnt in contours:
rect = cv2.boundingRect(cnt)
x, y, w, h = rect
if w*h > 40000:
mask = np.zeros(img.shape, np.uint8)
mask[y:y+h, x:x+w] = img[y:y+h, x:x+w]
brightness = np.sum(mask)
if brightness > max_brightness:
brightest_rectangle = rect
max_brightness = brightness
x, y, w, h = brightest_rectangle
crop_img = img[y:y+h, x:x+w]
#cropped image will hold the cheque (crop_img)
date = crop_img[int(h*0.07):int(h*0.12), int(w*0.75):int(w*0.965)]
name = crop_img[int(h*0.17):int(h*0.27), int(w*0.07):int(w*0.6)]
amt_words1 = crop_img[int(h*0.28):int(h*0.36), int(w*0.15):int(w*0.72)]
amt_words2 = crop_img[int(h*0.36):int(h*0.45), int(w*0.03):int(w*0.65)]
amt_no = crop_img[int(h*0.36):int(h*0.45), int(w*0.77):int(w*0.97)]
acc_no = crop_img[int(h*0.49):int(h*0.55), int(w*0.09):int(w*0.40)]
micr_code = crop_img[int(h*0.85):int(h*0.95), int(w*0.2):int(w*0.75)]
cv2.imshow('name',micr_code)
call(name)
cv2.line
cv2.rectangle(canvas, (x, y), (x+w, y+h), (0, 255, 0), 3)
#cv2.imshow("canvas", canvas)
#cv2.imshow("asdasd", date)
#cv2.imwrite("result.jpg", canvas)
#cv2.waitKey(0)