adsasd
adsasd
import sys
import cv2
# Window title
self.setWindowTitle('Face Tagging')
# Image dimensions
self.imgwidth = 300
self.imgheight = 400
# Widgets
def setWidgets(self):
self.btn1 = QPushButton('Upload image', self)
self.btn1.clicked.connect(self.getImagePath)
self.btn2 = QPushButton('Edit image', self)
self.btn2.clicked.connect(self.createEditingWindow)
self.btn3 = QPushButton('Tag faces', self)
self.btn3.clicked.connect(self.findFace)
self.btn4 = QPushButton('4', self)
self.btn5 = QPushButton('5', self)
self.btn6 = QPushButton('6', self)
# Image area
self.label = QLabel('Your image will show up here.\nONLY JPEG IS
SUPPORTED.', self)
# vbox as a widget
buttons_widget = QWidget()
buttons_widget.setLayout(vbox)
# hbox as a widget
t = QWidget()
t.setLayout(hbox)
# Window layout
self.setLayout(vbox2)
self.loadImage()
# Show image
def loadImage(self):
# Image as a QPixmap object
self.pixmap = QPixmap(self.imagepath)
def findFace(self):
self.fList = FaceList()
# Parameter 1 : image
# Parameter 2 : scale factor; high/low factor for faster/precise processing
# Parameter 3 : high/low for rigorous/lenient processing
# faces is the list of (x, y, w, h)'s - the top left coordinates, rectangle
width, and height, resp.
faces = face_cascade.detectMultiScale(grey, 1.2, 1) # .tolist()
cnt = 0
for (x, y, w, h) in faces:
# Logging in the terminal
# print("Tagged :", x, y, w, h)
print("Tagged :", x + w//2, y + h//2, (w+h)//4)
cnt += 1
self.showImage(img)
# RGB to BGR
self.image = image.rgbSwapped()
self.label.setPixmap(QPixmap.fromImage(self.image))
def setWidgets(self):
self.labelwidth = QLabel('Set width')
self.textwidth = QLineEdit(str(win.imgwidth), self)
self.labelheight = QLabel('Set height')
self.textheight = QLineEdit(str(win.imgheight), self)
self.labelcolour = QLabel('Recolour')
# Checked by default
self.radiobtn1.setChecked(True)
self.radiochecked = 'Original'
self.radiobtn2 = QRadioButton('Greyscale')
self.radiobtn3 = QRadioButton('R')
self.radiobtn4 = QRadioButton('G')
self.radiobtn5 = QRadioButton('B')
# Apply button
self.btnOK = QPushButton('Apply', self)
self.btnOK.clicked.connect(lambda: self.editImage())
# Set layout
self.setLayout(vbox)
def btnstate(self):
# sender() is the toggled radio button
radiobtn = self.sender()
self.radiochecked = radiobtn.text()
def editImage(self):
# Fetch from the input fields
imgwidth_edited = self.textwidth.text()
imgheight_edited = self.textheight.text()
try:
win.imgwidth = int(imgwidth_edited)
win.imgheight = int(imgheight_edited)
if self.radiochecked == 'Original':
img_edited = img
if self.radiochecked == 'Greyscale':
# 'L' is predefined for greyscale
img_edited = img.convert('L')
if self.radiochecked == 'R':
red = (
0.90, 0.36, 0.18, 0,
0.11, 0.72, 0.07, 0,
0.02, 0.12, 0.95, 0)
img_edited = img.convert('RGB', red)
if self.radiochecked == 'G':
green = (
0.41, 0.36, 0.18, 0,
0.50, 0.72, 0.07, 0,
0.02, 0.12, 0.95, 0)
img_edited = img.convert('RGB', green)
if self.radiochecked == 'B':
blue = (
0.31, 0.36, 0.18, 0,
0.40, 0.72, 0.07, 0,
0.60, 0.12, 0.95, 0)
img_edited = img.convert('RGB', blue)
win.loadImage()
# Reload image
win.loadImage()
class Face:
def __init__(self, x, y, w, h, name, idx):
self.x = x
self.y = y
self.w = w
self.h = h
self.name = name
self.idx = idx
class FaceList:
def __init__(self):
self.face_list = []
self.next_idx = 0
def append_face(self, x, y, w, h):
self. face_list.append(Face(x, y, w, h, "", self.next_idx))
self.next_idx += 1
# Main
if __name__ == '__main__':
app = QApplication(sys.argv)
win = MainWindow()
win.setWidgets()
win.show()
app.exec_()