Skip to content

Commit

Permalink
Added options changing
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkonrom committed Nov 29, 2017
1 parent b6c87c7 commit fadbbd7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 15 deletions.
15 changes: 15 additions & 0 deletions python/face_recognition_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import cv2
import face_recognition
from python.operation import Operation
import numpy as np
from PIL import Image

class FaceRecognition(Operation):
@staticmethod
def execute(input_image):
img = np.array(input_image)
img = img[:, :, ::-1].copy()
face_locations = face_recognition.face_locations(img)
for (top, right, bottom, left) in face_locations:
cv2.rectangle(img, (left, top), (right, bottom), (0,0,255), 2)
return Image.fromarray(img)
11 changes: 11 additions & 0 deletions python/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from python.operation import qpixmap_to_pil_image
from python.operation import image_to_qimage
from python.saliency import Saliency
from python.face_recognition_ import FaceRecognition

class MyWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
Expand All @@ -20,6 +21,7 @@ def __init__(self, parent=None):
self.ui.boundariesButton.clicked.connect(self.get_boundaries)
self.ui.semanticSegmentationButton.clicked.connect(self.get_semantic_segmentation)
self.ui.pushButtonImageSaliency.clicked.connect(self.get_saliency)
self.ui.pushButtonFaceRecognition.clicked.connect(self.get_face_recognition)

self.ui.keepAspectRatioCheckBox.stateChanged.connect(self.ui.inputLabel.setKeepAspectRatioEnabled)
self.ui.keepAspectRatioCheckBox.stateChanged.connect(self.ui.outputLabel.setKeepAspectRatioEnabled)
Expand All @@ -33,22 +35,31 @@ def load_image(self):
self.ui.inputLabel.loadPixmapData(input_pixmap)

def get_boundaries(self):
self.ui.stackedWidget.setCurrentIndex(0)
if self.ui.inputLabel.pixmap() is not None:
filter_number = 1 if self.ui.radioButtonRoberts.isChecked() else 2 if \
self.ui.radioButtonPrewitt.isChecked() else 3 if self.ui.radioButtonSobel.isChecked() else 4
self.ui.outputLabel.loadPixmapData(QPixmap.fromImage(image_to_qimage(BoundariesOperation.execute(
qpixmap_to_pil_image(self.ui.inputLabel.pixmap()), filter_number))))

def get_semantic_segmentation(self):
self.ui.stackedWidget.setCurrentIndex(1)
if self.ui.inputLabel.pixmap() is not None:
self.ui.outputLabel.loadPixmapData(QPixmap.fromImage(image_to_qimage(SemanticSegmentation.execute(
qpixmap_to_pil_image(self.ui.inputLabel.pixmap())))))

def get_saliency(self):
self.ui.stackedWidget.setCurrentIndex(2)
if self.ui.inputLabel.pixmap() is not None:
self.ui.outputLabel.loadPixmapData(QPixmap.fromImage(image_to_qimage(Saliency.execute(qpixmap_to_pil_image(
self.ui.inputLabel.pixmap())))))

def get_face_recognition(self):
self.ui.stackedWidget.setCurrentIndex(3)
if self.ui.inputLabel.pixmap() is not None:
self.ui.outputLabel.loadPixmapData(QPixmap.fromImage(image_to_qimage(FaceRecognition.execute(
qpixmap_to_pil_image(self.ui.inputLabel.pixmap())))))



if __name__ == "__main__":
Expand Down
22 changes: 21 additions & 1 deletion python/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ def setupUi(self, MainWindow):
self.groupBox_3.setObjectName("groupBox_3")
self.verticalLayout_3.addWidget(self.groupBox_3)
self.stackedWidget.addWidget(self.page_2)
self.page_3 = QtWidgets.QWidget()
self.page_3.setObjectName("page_3")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.page_3)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.groupBox_4 = QtWidgets.QGroupBox(self.page_3)
self.groupBox_4.setObjectName("groupBox_4")
self.horizontalLayout_5.addWidget(self.groupBox_4)
self.stackedWidget.addWidget(self.page_3)
self.page_4 = QtWidgets.QWidget()
self.page_4.setObjectName("page_4")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.page_4)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.groupBox_5 = QtWidgets.QGroupBox(self.page_4)
self.groupBox_5.setObjectName("groupBox_5")
self.horizontalLayout_6.addWidget(self.groupBox_5)
self.stackedWidget.addWidget(self.page_4)
self.verticalLayout_2.addWidget(self.stackedWidget)
self.horizontalLayout_3.addLayout(self.verticalLayout_2)
self.gridLayout.addWidget(self.groupBox, 0, 2, 1, 1)
Expand Down Expand Up @@ -179,10 +197,12 @@ def retranslateUi(self, MainWindow):
self.radioButtonScharr.setText(_translate("MainWindow", "Scharr filter"))
self.radioButtonSobel.setText(_translate("MainWindow", "Sobel filter"))
self.groupBox_3.setTitle(_translate("MainWindow", "Semantis segentation options"))
self.groupBox_4.setTitle(_translate("MainWindow", "Saliency options"))
self.groupBox_5.setTitle(_translate("MainWindow", "Face Recognition options"))
self.ignoreOverscaleCheckBox.setText(_translate("MainWindow", "Ignore original size"))
self.keepAspectRatioCheckBox.setText(_translate("MainWindow", "Maintain propotions"))
self.loadButton.setText(_translate("MainWindow", "Load"))
self.pushButtonExportSettings.setText(_translate("MainWindow", "Export settings"))
self.pushButtonExportSettings.setText(_translate("MainWindow", "Export options"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.actionOpen.setText(_translate("MainWindow", "Open"))
self.actionSave.setText(_translate("MainWindow", "Save"))
Expand Down
24 changes: 23 additions & 1 deletion python/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page_3">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Saliency options</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_4">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Face Recognition options</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -253,7 +275,7 @@
<item>
<widget class="QPushButton" name="pushButtonExportSettings">
<property name="text">
<string>Export settings</string>
<string>Export options</string>
</property>
</widget>
</item>
Expand Down
14 changes: 1 addition & 13 deletions python/saliency.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,4 @@ def execute(input_image):

mask = Saliency.backprojection_saliency(img)
segmentation = img * mask[:, :, np.newaxis]
return Image.fromarray(segmentation)

"""
if __name__ == "__main__":
name = sys.argv[1].strip(".jpg")
img = cv2.imread(sys.argv[1], 1)
cv2.imshow("original", img)
cv2.imshow("segmentation", segmentation)
cv2.waitKey(-1)
"""
return Image.fromarray(segmentation)

0 comments on commit fadbbd7

Please sign in to comment.