Skip to content

Commit

Permalink
Added command line parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkonrom committed Nov 29, 2017
1 parent fadbbd7 commit d87a8bb
Show file tree
Hide file tree
Showing 11 changed files with 930 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import argparse

def createParser():
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--infld')
parser.add_argument('-o', '--outfld')
parser.add_argument('--exec', choices=['boundaries', 'semantic_segmentation', 'saliency', 'face_recognition'])
parser.add_argument('--singleproc', action='store_true', default=False)
return parser



23 changes: 23 additions & 0 deletions boundaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from PyQt5.QtGui import QImage
from PIL import Image
from PyQt5.QtGui import QPixmap
from matplotlib import pyplot as plt
from operation import *
import numpy as np
from skimage.filters import roberts, sobel, scharr, prewitt


class BoundariesOperation(Operation):
@staticmethod
def execute(input_image, filter_number):
grayscale = input_image.convert('L')
if filter_number == 1:
edges = roberts(grayscale)
elif filter_number == 2:
edges = prewitt(grayscale)
elif filter_number == 3:
edges = scharr(grayscale)
elif filter_number == 4:
edges = sobel(grayscale)
array = np.uint8(plt.cm.gist_earth(edges) * 255)
return Image.fromarray(array).convert(mode='L')
3 changes: 3 additions & 0 deletions converter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
pyuic5 mainwindow.ui -o mainwindow.py

15 changes: 15 additions & 0 deletions face_recognition_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import cv2
import face_recognition
from operation import Operation
import numpy as np
from PIL import Image

class FaceRecognition(Operation):
@staticmethod
def execute(input_image, colors, width):
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), (colors[0], colors[1], colors[2]), width)
return Image.fromarray(img)
73 changes: 73 additions & 0 deletions imager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import sys
from api import createParser
from PyQt5 import Qt, QtWidgets
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QFileDialog
from boundaries import BoundariesOperation
from semantic_segmentation import SemanticSegmentation
from mainwindow import *
from operation import qpixmap_to_pil_image
from operation import image_to_qimage
from saliency import Saliency
from face_recognition_ import FaceRecognition


class MyWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

self.ui.loadButton.clicked.connect(self.load_image)

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)
self.ui.ignoreOverscaleCheckBox.stateChanged.connect(self.ui.inputLabel.setOverscaleEnabled)
self.ui.ignoreOverscaleCheckBox.stateChanged.connect(self.ui.outputLabel.setOverscaleEnabled)

def load_image(self):
input_image_path = QFileDialog.getOpenFileName(self, 'Open image...', '/home/nikita/Изображения/')[0]
if input_image_path:
input_pixmap = Qt.QPixmap(input_image_path)
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__":
parser = createParser()
namespace = parser.parse_args()
print(namespace)
#app = QtWidgets.QApplication(sys.argv)
#myapp = MyWin()
#myapp.show()
#sys.exit(app.exec_())
227 changes: 227 additions & 0 deletions mainwindow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.7
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(890, 519)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("C:/Users/jeavr/Desktop/unnamed.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setObjectName("groupBox")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.groupBox)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.boundariesButton = QtWidgets.QPushButton(self.groupBox)
self.boundariesButton.setObjectName("boundariesButton")
self.verticalLayout_2.addWidget(self.boundariesButton)
self.semanticSegmentationButton = QtWidgets.QPushButton(self.groupBox)
self.semanticSegmentationButton.setObjectName("semanticSegmentationButton")
self.verticalLayout_2.addWidget(self.semanticSegmentationButton)
self.pushButtonImageSaliency = QtWidgets.QPushButton(self.groupBox)
self.pushButtonImageSaliency.setObjectName("pushButtonImageSaliency")
self.verticalLayout_2.addWidget(self.pushButtonImageSaliency)
self.pushButtonFaceRecognition = QtWidgets.QPushButton(self.groupBox)
self.pushButtonFaceRecognition.setObjectName("pushButtonFaceRecognition")
self.verticalLayout_2.addWidget(self.pushButtonFaceRecognition)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem)
self.stackedWidget = QtWidgets.QStackedWidget(self.groupBox)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.stackedWidget.sizePolicy().hasHeightForWidth())
self.stackedWidget.setSizePolicy(sizePolicy)
self.stackedWidget.setObjectName("stackedWidget")
self.page = QtWidgets.QWidget()
self.page.setObjectName("page")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.page)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.groupBox_2 = QtWidgets.QGroupBox(self.page)
self.groupBox_2.setObjectName("groupBox_2")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.groupBox_2)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.radioButtonRoberts = QtWidgets.QRadioButton(self.groupBox_2)
self.radioButtonRoberts.setChecked(True)
self.radioButtonRoberts.setObjectName("radioButtonRoberts")
self.verticalLayout_4.addWidget(self.radioButtonRoberts)
self.radioButtonPrewitt = QtWidgets.QRadioButton(self.groupBox_2)
self.radioButtonPrewitt.setObjectName("radioButtonPrewitt")
self.verticalLayout_4.addWidget(self.radioButtonPrewitt)
self.radioButtonScharr = QtWidgets.QRadioButton(self.groupBox_2)
self.radioButtonScharr.setObjectName("radioButtonScharr")
self.verticalLayout_4.addWidget(self.radioButtonScharr)
self.radioButtonSobel = QtWidgets.QRadioButton(self.groupBox_2)
self.radioButtonSobel.setObjectName("radioButtonSobel")
self.verticalLayout_4.addWidget(self.radioButtonSobel)
self.horizontalLayout_4.addWidget(self.groupBox_2)
self.stackedWidget.addWidget(self.page)
self.page_2 = QtWidgets.QWidget()
self.page_2.setObjectName("page_2")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.page_2)
self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.groupBox_3 = QtWidgets.QGroupBox(self.page_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.groupBox_3.sizePolicy().hasHeightForWidth())
self.groupBox_3.setSizePolicy(sizePolicy)
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, 3, 1, 1)
self.outputLabel = ScaledPixmap(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.outputLabel.sizePolicy().hasHeightForWidth())
self.outputLabel.setSizePolicy(sizePolicy)
self.outputLabel.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.outputLabel.setFrameShadow(QtWidgets.QFrame.Sunken)
self.outputLabel.setLineWidth(1)
self.outputLabel.setText("")
self.outputLabel.setScaledContents(False)
self.outputLabel.setObjectName("outputLabel")
self.gridLayout.addWidget(self.outputLabel, 0, 1, 1, 1)
self.inputLabel = ScaledPixmap(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.inputLabel.sizePolicy().hasHeightForWidth())
self.inputLabel.setSizePolicy(sizePolicy)
self.inputLabel.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.inputLabel.setFrameShadow(QtWidgets.QFrame.Sunken)
self.inputLabel.setLineWidth(1)
self.inputLabel.setText("")
self.inputLabel.setScaledContents(False)
self.inputLabel.setObjectName("inputLabel")
self.gridLayout.addWidget(self.inputLabel, 0, 0, 1, 1)
self.line_2 = QtWidgets.QFrame(self.centralwidget)
self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_2.setObjectName("line_2")
self.gridLayout.addWidget(self.line_2, 0, 2, 1, 1)
self.horizontalLayout.addLayout(self.gridLayout)
self.verticalLayout.addLayout(self.horizontalLayout)
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.verticalLayout.addWidget(self.line)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.ignoreOverscaleCheckBox = QtWidgets.QCheckBox(self.centralwidget)
self.ignoreOverscaleCheckBox.setAcceptDrops(False)
self.ignoreOverscaleCheckBox.setChecked(True)
self.ignoreOverscaleCheckBox.setObjectName("ignoreOverscaleCheckBox")
self.horizontalLayout_2.addWidget(self.ignoreOverscaleCheckBox)
self.keepAspectRatioCheckBox = QtWidgets.QCheckBox(self.centralwidget)
self.keepAspectRatioCheckBox.setChecked(True)
self.keepAspectRatioCheckBox.setObjectName("keepAspectRatioCheckBox")
self.horizontalLayout_2.addWidget(self.keepAspectRatioCheckBox)
self.loadButton = QtWidgets.QPushButton(self.centralwidget)
self.loadButton.setObjectName("loadButton")
self.horizontalLayout_2.addWidget(self.loadButton)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout_2.addWidget(self.pushButton)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem1)
self.pushButtonExportSettings = QtWidgets.QPushButton(self.centralwidget)
self.pushButtonExportSettings.setObjectName("pushButtonExportSettings")
self.horizontalLayout_2.addWidget(self.pushButtonExportSettings)
self.verticalLayout.addLayout(self.horizontalLayout_2)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 890, 22))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionOpen = QtWidgets.QAction(MainWindow)
self.actionOpen.setObjectName("actionOpen")
self.actionSave = QtWidgets.QAction(MainWindow)
self.actionSave.setObjectName("actionSave")
self.actionExit = QtWidgets.QAction(MainWindow)
self.actionExit.setObjectName("actionExit")
self.actionOpen_2 = QtWidgets.QAction(MainWindow)
self.actionOpen_2.setObjectName("actionOpen_2")
self.actionOpen_3 = QtWidgets.QAction(MainWindow)
self.actionOpen_3.setObjectName("actionOpen_3")
self.menubar.addAction(self.menuFile.menuAction())

self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Imager"))
self.groupBox.setTitle(_translate("MainWindow", "Controlls"))
self.boundariesButton.setText(_translate("MainWindow", "Boundaries"))
self.semanticSegmentationButton.setText(_translate("MainWindow", "Semantic Segmentation"))
self.pushButtonImageSaliency.setText(_translate("MainWindow", "Saliency"))
self.pushButtonFaceRecognition.setText(_translate("MainWindow", "Face Recognition"))
self.groupBox_2.setTitle(_translate("MainWindow", "Boundaries options"))
self.radioButtonRoberts.setText(_translate("MainWindow", "Roberts filter"))
self.radioButtonPrewitt.setText(_translate("MainWindow", "Prewitt filter"))
self.radioButtonScharr.setText(_translate("MainWindow", "Scharr filter"))
self.radioButtonSobel.setText(_translate("MainWindow", "Sobel filter"))
self.groupBox_3.setTitle(_translate("MainWindow", "Semantis Segmentation 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.pushButton.setText(_translate("MainWindow", "Save"))
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"))
self.actionExit.setText(_translate("MainWindow", "Exit"))
self.actionOpen_2.setText(_translate("MainWindow", "Open"))
self.actionOpen_3.setText(_translate("MainWindow", "Open"))

from scaledpixmap import ScaledPixmap
Loading

0 comments on commit d87a8bb

Please sign in to comment.