diff --git a/main.py b/main.py new file mode 100644 index 0000000..58245b1 --- /dev/null +++ b/main.py @@ -0,0 +1,245 @@ +import sys +import cv2 +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * +from PyQt5.QtCore import * +import matplotlib.pyplot as plt + +from custom.stackedWidget import StackedWidget +from custom.treeView import FileSystemTreeView +from custom.listWidgets import FuncListWidget, UsedListWidget, FuncListWidget1, FuncListWidget2, FuncListWidget3, \ + FuncListWidget4, FuncListWidget5, FuncListWidget6, FuncListWidget7 +from custom.graphicsView import GraphicsView +from custom.treeWidgets import FuncTreeWidget + + +class MyApp(QMainWindow): + def __init__(self): + super(MyApp, self).__init__() + self.tool_bar = self.addToolBar('工具栏') + self.action_right_rotate = QAction(QIcon("icons/右旋转.png"), "向右旋转90", self) + self.action_left_rotate = QAction(QIcon("icons/左旋转.png"), "向左旋转90°", self) + self.action_histogram = QAction(QIcon("icons/直方图.png"), "直方图", self) + self.action_right_rotate.triggered.connect(self.right_rotate) + self.action_left_rotate.triggered.connect(self.left_rotate) + self.action_histogram.triggered.connect(self.histogram) + self.tool_bar.addActions((self.action_left_rotate, self.action_right_rotate, self.action_histogram)) + + self.useListWidget = UsedListWidget(self) + self.funcListWidget = FuncListWidget(self) + self.funcListWidget1 = FuncListWidget1(self) + self.funcListWidget2 = FuncListWidget2(self) + self.funcListWidget3 = FuncListWidget3(self) + self.funcListWidget4 = FuncListWidget4(self) + self.funcListWidget5 = FuncListWidget5(self) + self.funcListWidget6 = FuncListWidget6(self) + self.funcListWidget7 = FuncListWidget7(self) + self.stackedWidget = StackedWidget(self) + self.fileSystemTreeView = FileSystemTreeView(self) + self.graphicsView = GraphicsView(self) + self.funcTreeWidget = FuncTreeWidget(self) + + self.dock_fun = QDockWidget(self) + self.dock_fun.setWidget(self.funcTreeWidget) + self.dock_fun.setTitleBarWidget(QLabel('图像操作')) + self.dock_fun.setFeatures(QDockWidget.NoDockWidgetFeatures) + self.dock_fun.setMaximumHeight(500) + + self.dock_file = QDockWidget(self) + self.dock_file.setWidget(self.fileSystemTreeView) + self.dock_file.setTitleBarWidget(QLabel('目录')) + self.dock_file.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_func = QDockWidget(self) + self.dock_func.setWidget(self.funcListWidget) + self.dock_func.setTitleBarWidget(QLabel('其他操作')) + self.dock_func.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_func1 = QDockWidget(self) + self.dock_func1.setWidget(self.funcListWidget1) + self.dock_func1.setTitleBarWidget(QLabel('裁剪')) + self.dock_func1.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_func2 = QDockWidget(self) + self.dock_func2.setWidget(self.funcListWidget2) + self.dock_func2.setTitleBarWidget(QLabel('光效')) + self.dock_func2.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_func3 = QDockWidget(self) + self.dock_func3.setWidget(self.funcListWidget3) + self.dock_func3.setTitleBarWidget(QLabel('色彩')) + self.dock_func3.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_func4 = QDockWidget(self) + self.dock_func4.setWidget(self.funcListWidget4) + self.dock_func4.setTitleBarWidget(QLabel('HSL')) + self.dock_func4.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_func5 = QDockWidget(self) + self.dock_func5.setWidget(self.funcListWidget5) + self.dock_func5.setTitleBarWidget(QLabel('特效')) + self.dock_func5.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_func6 = QDockWidget(self) + self.dock_func6.setWidget(self.funcListWidget6) + self.dock_func6.setTitleBarWidget(QLabel('风格迁移')) + self.dock_func6.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_func7 = QDockWidget(self) + self.dock_func7.setWidget(self.funcListWidget7) + self.dock_func7.setTitleBarWidget(QLabel('质感')) + self.dock_func7.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_used = QDockWidget(self) + self.dock_used.setWidget(self.useListWidget) + self.dock_used.setTitleBarWidget(QLabel('已选操作')) + self.dock_used.setFeatures(QDockWidget.NoDockWidgetFeatures) + self.dock_used.setFeatures(QDockWidget.NoDockWidgetFeatures) + + self.dock_attr = QDockWidget(self) + self.dock_attr.setWidget(self.stackedWidget) + self.dock_attr.setTitleBarWidget(QLabel('属性')) + self.dock_attr.setFeatures(QDockWidget.NoDockWidgetFeatures) + self.dock_attr.close() + + self.setCentralWidget(self.graphicsView) + self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_file) + self.addDockWidget(Qt.RightDockWidgetArea, self.dock_attr) + self.addDockWidget(Qt.RightDockWidgetArea, self.dock_fun) + self.splitDockWidget(self.dock_fun, self.dock_func, Qt.Vertical) + self.splitDockWidget(self.dock_file, self.dock_used, Qt.Vertical) + self.dock_func1.hide() + self.dock_func2.hide() + self.dock_func3.hide() + self.dock_func4.hide() + self.dock_func5.hide() + self.dock_func6.hide() + self.dock_func7.hide() + self.setWindowTitle('Opencv图像处理') + self.setWindowIcon(QIcon('icons/main.png')) + self.src_img = None + self.cur_img = None + + def update_dock(self, item): + if item == "裁剪": + self.dock_func1.show() + self.dock_func2.hide() + self.dock_func3.hide() + self.dock_func4.hide() + self.dock_func5.hide() + self.dock_func6.hide() + self.dock_func7.hide() + self.dock_func.hide() + self.splitDockWidget(self.dock_fun, self.dock_func1, Qt.Vertical) + elif item == "光效": + self.dock_func1.hide() + self.dock_func2.show() + self.dock_func3.hide() + self.dock_func4.hide() + self.dock_func5.hide() + self.dock_func6.hide() + self.dock_func7.hide() + self.dock_func.hide() + self.splitDockWidget(self.dock_fun, self.dock_func2, Qt.Vertical) + elif item == "色彩": + self.dock_func1.hide() + self.dock_func2.hide() + self.dock_func3.show() + self.dock_func4.hide() + self.dock_func5.hide() + self.dock_func6.hide() + self.dock_func7.hide() + self.dock_func.hide() + self.splitDockWidget(self.dock_fun, self.dock_func3, Qt.Vertical) + elif item == "HSL": + self.dock_func1.hide() + self.dock_func2.hide() + self.dock_func3.hide() + self.dock_func4.show() + self.dock_func5.hide() + self.dock_func6.hide() + self.dock_func7.hide() + self.dock_func.hide() + self.splitDockWidget(self.dock_fun, self.dock_func4, Qt.Vertical) + elif item == "特效": + self.dock_func1.hide() + self.dock_func2.hide() + self.dock_func3.hide() + self.dock_func4.hide() + self.dock_func5.show() + self.dock_func6.hide() + self.dock_func7.hide() + self.dock_func.hide() + self.splitDockWidget(self.dock_fun, self.dock_func5, Qt.Vertical) + elif item == "风格迁移": + self.dock_func1.hide() + self.dock_func2.hide() + self.dock_func3.hide() + self.dock_func4.hide() + self.dock_func5.hide() + self.dock_func6.show() + self.dock_func7.hide() + self.dock_func.hide() + self.splitDockWidget(self.dock_fun, self.dock_func6, Qt.Vertical) + elif item == "其他操作": + self.dock_func1.hide() + self.dock_func2.hide() + self.dock_func3.hide() + self.dock_func4.hide() + self.dock_func5.hide() + self.dock_func6.hide() + self.dock_func7.hide() + self.dock_func.show() + self.splitDockWidget(self.dock_fun, self.dock_func, Qt.Vertical) + elif item == "质感": + self.dock_func1.hide() + self.dock_func2.hide() + self.dock_func3.hide() + self.dock_func4.hide() + self.dock_func5.hide() + self.dock_func6.hide() + self.dock_func7.show() + self.dock_func.hide() + self.splitDockWidget(self.dock_fun, self.dock_func7, Qt.Vertical) + + def update_image(self): + if self.src_img is None: + return + img = self.process_image() + self.cur_img = img + self.graphicsView.update_image(img) + + def change_image(self, img): + self.src_img = img + img = self.process_image() + self.cur_img = img + self.graphicsView.change_image(img) + + def process_image(self): + img = self.src_img.copy() + for i in range(self.useListWidget.count()): + img = self.useListWidget.item(i)(img) + return img + + def right_rotate(self): + self.graphicsView.rotate(90) + + def left_rotate(self): + self.graphicsView.rotate(-90) + + def histogram(self): + color = ('b', 'g', 'r') + for i, col in enumerate(color): + histr = cv2.calcHist([self.cur_img], [i], None, [256], [0, 256]) + histr = histr.flatten() + plt.plot(range(256), histr, color=col) + plt.xlim([0, 256]) + plt.show() + + +if __name__ == "__main__": + app = QApplication(sys.argv) + app.setStyleSheet(open('./custom/styleSheet.qss', encoding='utf-8').read()) + window = MyApp() + window.show() + sys.exit(app.exec_())