-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
162 lines (123 loc) · 4.67 KB
/
app.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from logging import debug
from flask import Flask, flash, render_template, request, jsonify
from apps.main_torch import *
from apps.main_cv2 import *
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import io
import cv2
# opencv-python==4.5.3.56
app = Flask(__name__)
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'jfif'}
def allowed_file(filename):
return '.' in filename and filename.rsplit('.',1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET'])
def hello_world():
src=""
return render_template('index.html', aaaa=src)
@app.route('/trilha', methods=['GET'])
def trilha():
return render_template('home-trail.html')
@app.route('/upload', methods=['GET'])
def enviar():
return render_template('upload.html')
@app.route('/classificacao', methods=['POST'])
def previsao():
if request.method == 'POST':
file = request.files.get('file')
src = request.form.get('invisivel')
# print(src)
if file is None or file.filename == '':
return render_template('upload.html', previsao="Sem arquivo.")
# return jsonify({'error': 'no file'})
if not allowed_file(file.filename):
# return jsonify({'error': 'format not supported'})
return render_template('upload.html', previsao="Formato não suportado.")
else:
img_bytes = file.read()
# print(type(img_bytes))
image = Image.open(io.BytesIO(img_bytes)) #imagem PIL
# print(type(image))
buff = np.fromstring(img_bytes, np.uint8)
# print(type(buff))
buff = buff.reshape(1, -1)
# print(type(buff))
img = cv2.imdecode(buff, cv2.IMREAD_GRAYSCALE )
# print(type(img))
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) #imagem cv2 pronta para ser trabalhada
# print(type(img))
# buff = np.fromstring(img_bytes, np.uint8)
# buff = buff.reshape(1, -1)
# img = cv2.imdecode(buff, cv2.IMREAD_COLOR)
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) #imagem cv2 pronta para ser trabalhada
lista_blocos = corta3x3(img)
lista_blocos_PIL = cv2_to_PIL(lista_blocos)
resultado = quantos_verificou(lista_blocos_PIL)
if resultado[0]>0:
fusivel = f'Quantidade de Fusível: {resultado[0]}'
else:
fusivel = 0
if resultado[1]>0:
rele = f'Quantidade de Relé: {resultado[1]}'
else:
rele = 0
if resultado[2]>0:
capacitor = f'Quantidade de Capacitor Eletrolítico: {resultado[2]}'
else:
capacitor = 0
if resultado[3]>0:
led = f'Quantidade de LED: {resultado[3]}'
else:
led = 0
prev = 0
title = "1"
# fusivel, rele, capacitor, led = 0,0,0,0
# tensor = transform_image(image)
# img = Image.open(src)
# plt.imshow(img)
# return "Imagem transformada em tensor e pronto para a classificação: " + str(tensor)
# prev = str(tensor)
return render_template('upload.html', previsao=prev, title=title, aaaa=src, result1=fusivel, result2=rele, result3=capacitor, result4=led)
@app.route('/t1', methods=['GET'])
def t1():
return render_template('trail-content-1.html')
@app.route('/t2', methods=['GET'])
def t2():
return render_template('trail-content-2.html')
@app.route('/t3', methods=['GET'])
def t3():
return render_template('trail-content-3.html')
@app.route('/t4', methods=['GET'])
def t4():
return render_template('trail-content-4.html')
@app.route('/t5', methods=['GET'])
def t5():
return render_template('trail-content-5.html')
@app.route('/t6', methods=['GET'])
def t6():
return render_template('trail-content-6.html')
@app.route('/t7', methods=['GET'])
def t7():
return render_template('trail-content-7.html')
@app.route('/t8', methods=['GET'])
def t8():
return render_template('trail-content-8.html')
@app.route('/t9', methods=['GET'])
def t9():
return render_template('trail-content-9.html')
@app.route('/t10', methods=['GET'])
def t10():
return render_template('trail-content-10.html')
@app.route('/t11', methods=['GET'])
def t11():
return render_template('trail-content-11.html')
@app.route('/t12', methods=['GET'])
def t12():
return render_template('trail-content-12.html')
@app.route('/t13', methods=['GET'])
def t13():
return render_template('trail-content-13.html')
if __name__ == '__main__':
app.secret_key = 'ItIsASecret'
app.run( debug=True)