-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathsimple_gui.py
55 lines (44 loc) · 1.66 KB
/
simple_gui.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
import os, threading, webbrowser
from flask import Flask, request, render_template, Response
from Imagehandler import Imagehandler
app = Flask(__name__, static_folder='Input')
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
dest = []
def gen(destination):
import cv2
obj = Imagehandler(str(destination))
TransformImage = obj.QRCodeInImage()
ret, frame = cv2.imencode('.jpg', TransformImage)
frame = frame.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/image_feed')
def image_feed():
return Response(gen(dest[0]),
mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route("/")
def index():
return render_template("upload.html")
@app.route("/upload", methods=["POST"])
def upload():
target = os.path.join(APP_ROOT, 'Input/')
print(target)
if not os.path.isdir(target):
os.mkdir(target)
else:
print("Couldn't create upload directory: {}".format(target))
print(request.files.getlist("file"))
for upload in request.files.getlist("file"):
print(upload)
print("{} is the file name".format(upload.filename))
filename = upload.filename
destination = "/".join([target, filename])
print ("Accept incoming file:", filename)
print ("Save it to:", destination)
upload.save(destination)
dest.append(destination)
return render_template("complete.html", image_name=filename)
if __name__ == "__main__":
url = 'http://127.0.0.1:{0}'.format(5000)
threading.Timer(1.25, lambda : webbrowser.open(url)).start()
app.run(port=5000, debug=False)