-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
89 lines (67 loc) · 2.54 KB
/
main.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
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
from flask import Flask, request, redirect, render_template, url_for
from processor import *
app = Flask(__name__)
processor = Processor()
@app.route('/loadImage', methods = ['GET', 'POST'])
def loadImage():
if request.method == 'POST':
file = request.files['file']
return processor.load(file)
return render_template('load_image.html')
@app.route('/filters', methods = ['GET', 'POST'])
def filters():
if processor.inputImage['empty'] == True:
return redirect(url_for('loadImage'))
if request.method == 'POST':
params = request.form
operation = None
cont = 0
for i in processor.switcher.keys():
if cont == int(params['operation']):
operation = i
break
cont += 1
return processor.process(operation, params)
if request.method == 'GET':
imgBase64 = CVImageToBase64(processor.inputImage['img'])
print(imgBase64[:80])
operatorsList = processor.getOpList()
print(operatorsList)
page_corners = processor.getPoints()
return render_template(
'filters.html',
img = imgBase64,
opList = operatorsList,
top_left = page_corners[0], top_right = page_corners[1],
bot_left = page_corners[2], bot_right = page_corners[3]
)
@app.route('/scan', methods = ['GET', 'POST'])
def scan():
if processor.outputImage['empty'] == True:
return redirect(url_for('loadImage'))
if request.method == 'POST':
return processor.download()
imgBase64 = CVImageToBase64(processor.outputImage['img'])
print(imgBase64[:80])
return render_template('scan.html', img = imgBase64)
@app.route('/process', methods = ['GET', 'POST'])
def process():
if request.method == 'POST':
file = request.files['file']
return processor.process(file, request.form)
return render_template('scanner_form.html')
@app.route('/download', methods = ['GET'])
def download():
if processor.inputImage['empty'] == True:
return redirect(url_for('loadImage'))
return processor.download()
@app.route('/', methods = ['GET'])
def base():
return redirect(url_for('loadImage'))
if __name__ == '__main__':
app.secret_key = 'some secret key'
compileFlag = input('Do you want to compile C++ librarys? (Y/N): ')
if compileFlag == 'Y' or compileFlag == 'y':
cleanAfterBuildFlag = input('Do you want to clean after build? (Y/N): ')
processor.compileLibrary(cleanAfterBuildFlag)
app.run('0.0.0.0')