Skip to content

Commit 1fafa06

Browse files
committed
Changes, such as credits and really bad login
1 parent a0969d6 commit 1fafa06

32 files changed

Lines changed: 175 additions & 11 deletions

.DS_Store

0 Bytes
Binary file not shown.

server/.DS_Store

0 Bytes
Binary file not shown.

server/crop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ def ocr(filename):
5858
cv2.imwrite(f'static/images/canny/{filename}',cv2.resize(out, (640,350)))
5959
return text
6060

61-
ocr('image.jpg')
61+
text_data = ocr('image.jpg')
62+
print(text_data)

server/flaskserver.py

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,65 @@
44
from flask import Flask, redirect, url_for, request, render_template, flash, send_from_directory
55
from werkzeug.utils import secure_filename
66
from api import maincall, analyze
7+
import cv2
8+
import numpy as np
9+
from matplotlib import pyplot as plt
10+
from pytesseract import image_to_string
711

12+
def ocr(filename):
13+
img = cv2.imread(f'static/images/cheques/{filename}')
14+
15+
max_brightness = 0
16+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
17+
canvas = img.copy()
18+
#ret,thresh = cv2.threshold(gray,199,255,1)
19+
blur = cv2.medianBlur(img,5)
20+
edged = cv2.Canny(blur, 25, 70)
21+
contours,h= cv2.findContours(edged,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
22+
23+
cv2.drawContours(img, contours,-1, (0,255,0), 3)
24+
25+
for cnt in contours:
26+
rect = cv2.boundingRect(cnt)
27+
x, y, w, h = rect
28+
if w*h > 40000:
29+
mask = np.zeros(img.shape, np.uint8)
30+
mask[y:y+h, x:x+w] = img[y:y+h, x:x+w]
31+
brightness = np.sum(mask)
32+
if brightness > max_brightness:
33+
brightest_rectangle = rect
34+
max_brightness = brightness
35+
36+
x, y, w, h = brightest_rectangle
37+
crop_img = img[y:y+h, x:x+w]
38+
39+
edges = cv2.Canny(crop_img,101,200)
40+
41+
crop_img = img[y:y+h, x:x+w]
42+
cheque = {}
43+
44+
cheque['date'] = { 'bounds': (int(h*0.07), int(h*0.14), int(w*0.75),int(w*0.965) )}
45+
cheque['name'] = { 'bounds': (int(h*0.17), int(h*0.27), int(w*0.07),int(w*0.6) )}
46+
cheque['amt_words1'] = { 'bounds': (int(h*0.28), int(h*0.36), int(w*0.15),int(w*0.72) )}
47+
cheque['amt_words2'] = { 'bounds': (int(h*0.36), int(h*0.45), int(w*0.03),int(w*0.65) )}
48+
cheque['amt_no'] = { 'bounds': (int(h*0.36), int(h*0.45), int(w*0.77),int(w*0.97) )}
49+
cheque['acc_no'] = { 'bounds': (int(h*0.49), int(h*0.55), int(w*0.09),int(w*0.40) )}
50+
cheque['micr_code'] = { 'bounds': (int(h*0.85), int(h*0.95), int(w*0.2 ),int(w*0.75) )}
51+
52+
out = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
53+
text = {}
54+
55+
for f in cheque:
56+
y0, y1, x0, x1 = cheque[f]['bounds']
57+
crop_field = crop_img[y0:y1,x0:x1]
58+
cv2.rectangle(out, (x0,y0),(x1,y1), color=(0,255,0), thickness=3 )
59+
text[f] = image_to_string(crop_field)
60+
print(f, ':' , text[f])
61+
62+
63+
cv2.imwrite(f'static/images/cropped/{filename}',cv2.resize(crop_img, (640,350)))
64+
cv2.imwrite(f'static/images/canny/{filename}',cv2.resize(out, (640,350)))
65+
return text
866

967
UPLOAD_FOLDER = './static/images/cheques'
1068
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
@@ -42,6 +100,17 @@ def upload_file():
42100
with open('./static/data/'+filename[:-4]+'.txt','w') as fil:
43101
for key in field_list:
44102
fil.write(request.form[key]+'\n')
103+
text_data = ocr(file.filename)
104+
with open('./static/data/'+filename[:-4]+'_analyze.txt','w') as fil:
105+
fil.write('1950020'+'\n')
106+
fil.write(text_data['amt_words1']+'\n')
107+
fil.write(text_data['amt_no']+'\n')
108+
fil.write('__/__/____'+'\n')
109+
fil.write(text_data['micr_code'].split()[1]+'\n')
110+
fil.write(text_data['micr_code'].split()[3]+'\n')
111+
fil.write(text_data['name']+'\n')
112+
fil.write(text_data['acc_no']+'\n')
113+
fil.write(('yes'+'\n')*2)
45114
return redirect(url_for('gallery'))
46115
return render_template('upload.html')
47116

@@ -65,21 +134,38 @@ def evaluate(chq_num):
65134
user_data = dict()
66135
for i,val in enumerate(f.read().splitlines()):
67136
user_data[fields[i]] = val
137+
with open('./static/data/'+str(chq_num)[:-4]+'_analyze.txt') as f:
138+
eval_data = dict()
139+
for i,val in enumerate(f.read().splitlines()):
140+
eval_data[fields[i]] = val
68141
except:
69142
user_data = dict()
143+
eval_data = dict()
70144

71145
user_data['chq_num'] = chq_num
72-
eval_data = analyze(chq_num)
73146
return render_template('evaluate.html', eval_data=eval_data, user_data=user_data)
74147

75148
@app.route('/credits')
76149
def credits():
77150
return render_template('credits.html')
78151

79-
@app.route('/')
152+
@app.route('/index')
80153
def index():
81154
return render_template('index.html')
82155

156+
@app.route('/',methods=['GET', 'POST'])
157+
def login():
158+
if request.method == 'POST':
159+
if request.form['email'] == '[email protected]':
160+
if request.form['password'] == 'admin123':
161+
return redirect(url_for('index'))
162+
else:
163+
flash("Invalid Email or Password")
164+
elif request.form['password'] != 'admin123':
165+
flash("Invalid Email or Password")
166+
else:
167+
flash("Invalid Email or Password")
168+
return render_template('login.html')
169+
83170
if __name__ == '__main__':
84171
app.run(debug = True, host='0.0.0.0', port=8000)
85-

server/static/.DS_Store

2 KB
Binary file not shown.

server/static/images/cheques/squaredp_sm.jpg renamed to server/static/adish.jpg

File renamed without changes.

server/static/aniruddha.jpg

8.66 KB
Loading

server/static/css/style.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,21 @@
1111
}
1212
.icon-block .material-icons {
1313
font-size: inherit;
14+
}
15+
16+
#per1 {
17+
width: 50%;
18+
float: left;
19+
}
20+
#per_image{
21+
width: 200px;
22+
height: 200px;
23+
}
24+
#per_name{
25+
color: teal;
26+
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
27+
}
28+
29+
body {
30+
background-color: antiquewhite;
1431
}

server/static/data/950020.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1950020
2+
Ten thousand rupees only
3+
40,000 /-
4+
__/__/____
5+
695002032
6+
32
7+
Self
8+
00001234556001
9+
yes
10+
yes

0 commit comments

Comments
 (0)