-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.py
More file actions
86 lines (76 loc) · 3.2 KB
/
Copy pathGUI.py
File metadata and controls
86 lines (76 loc) · 3.2 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
import sys
import cv2
import numpy
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QVBoxLayout, QHBoxLayout, QPushButton, QFileDialog
from PyQt5.QtCore import Qt
import train
import detect
import config
import imutils
import argparse
import reconocer
class FaceGUI(QWidget):
def __init__(self):
super().__init__()
self.image = None
self.img = None
self.label = QLabel()
self.UI()
def UI(self):
self.label.setText('Proyecto R-Face')
self.label.setAlignment(Qt.AlignCenter)
self.label.setStyleSheet('border: gray; border-style:solid; border-width: 1px;')
btn_open = QPushButton('Abir Imagen...')
btn_open.clicked.connect(self.abrirImagen)
btn_procesar = QPushButton('Comenzar proceso de reconocimiento facial')
btn_procesar.clicked.connect(self.r_faces)
top_bar = QHBoxLayout()
top_bar.addWidget(btn_open)
top_bar.addWidget(btn_procesar)
root = QVBoxLayout(self)
root.addLayout(top_bar)
root.addWidget(self.label)
self.resize(540, 574)
self.setWindowTitle('Proyecto R-Face')
def abrirImagen(self):
filename, _ = QFileDialog.getOpenFileName(None, 'Elegir Imagen', '.', 'Image Files (*.png *.jpg *.jpeg *.bmp)')
self.img = filename
if filename:
with open(filename, "rb") as file:
data = numpy.array(bytearray(file.read()))
self.image = cv2.imdecode(data, cv2.IMREAD_UNCHANGED)
self.mostrarImagen()
def r_faces(self):
if self.image is not None:
faceCascade = cv2.CascadeClassifier('cascades/face.xml')
eyeCascade = cv2.CascadeClassifier('cascades/haarcascade_eye.xml')
faceSize = config.DEFAULT_FACE_SIZE
threshold = 500
recognizer = train.trainRecognizer('train', faceSize, showFaces=True)
capture = cv2.imread(self.img)
while True:
self.image = imutils.resize(capture, height=500)
for (label, confidence, (x, y, w, h)) in reconocer.RecognizeFace(self.image, faceCascade, eyeCascade, faceSize, threshold):
cv2.rectangle(self.image, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(self.image, "{} = {}".format(recognizer.getLabelInfo(label), int(confidence)), (x, y), cv2.FONT_HERSHEY_PLAIN, 1, (0,255,0), 1, cv2.LINE_AA)
self.mostrarImagen()
break
def mostrarImagen(self):
size = self.image.shape
step = self.image.size / size[0]
qformat = QImage.Format_Indexed8
if len(size) == 3:
if size[2] == 4:
qformat = QImage.Format_RGBA8888
else:
qformat = QImage.Format_RGB888
img = QImage(self.image, size[1], size[0], step, qformat)
img = img.rgbSwapped()
self.label.setPixmap(QPixmap.fromImage(img))
self.resize(self.label.pixmap().size())
if __name__ == '__main__':
app = QApplication(sys.argv)
win = FaceGUI()
win.show()
sys.exit(app.exec_())