프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / SymbolThicknessDialog.py @ 0ae849c3

이력 | 보기 | 이력해설 | 다운로드 (2.59 KB)

1
# -*- coding: utf-8 -*-
2

    
3
from PyQt5 import QtCore, QtGui, QtWidgets
4
from PyQt5.QtWidgets import *
5
import os, sys
6
from AppDocData import AppDocData
7
import SymbolThickness_UI
8
import cv2
9
import numpy as np
10

    
11
class QSymbolThicknessDialog(QDialog):
12
    def __init__(self, parent):
13
        QDialog.__init__(self, parent)
14

    
15
        self.ui = SymbolThickness_UI.Ui_SymbolThicknessDialog()
16
        self.ui.setupUi(self)
17
        self.isAccepted = False
18
        
19
        configs = AppDocData.instance().getConfigs('Filter', 'DilateSize')
20
        self.ui.spinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxDilateSize.setValue(0)
21

    
22
    def showDialog(self):
23
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
24
        self.exec_()
25
        return self.isAccepted, self.angle, self.sx, self.sy, self.sz
26

    
27
    def accept(self):
28
        size = self.ui.spinBox.value()
29
        if size:
30
            reply = QMessageBox.question(self, self.tr('Continue?'), self.tr('Are you sure to continue?'), QMessageBox.Yes, QMessageBox.Cancel)
31
            if reply == QMessageBox.Yes:
32
                try:
33
                    project = AppDocData.instance().getCurrentProject()
34
                    rootPath = project.getImageFilePath()
35
                    rootList = os.listdir(rootPath)
36

    
37
                    for folder in rootList:
38
                        path = os.path.join(rootPath, folder)
39
                        imgList = os.listdir(path)
40

    
41
                        for imgPath in imgList:
42
                            fullPath = os.path.join(path, imgPath)
43
                            img = cv2.imread(fullPath, cv2.IMREAD_GRAYSCALE)
44
                            kernel = np.ones((size, size), np.uint8)
45

    
46
                            height, width = img.shape[0], img.shape[1]
47
                            new = np.ones((height + 2 * size, width + 2 * size), np.uint8) * 255
48
                            new[size:size+height, size:size+width] = img
49

    
50
                            e = cv2.erode(new, kernel, iterations=1)
51
                            cv2.imwrite(fullPath, e)
52

    
53
                    QMessageBox.information(self, self.tr('Information'), self.tr('Succeeded'))
54
                except Exception as ex:
55
                    from App import App
56
                    from AppDocData import MessageType
57

    
58
                    message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
59
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
60

    
61
            QDialog.accept(self)
62

    
63
    def reject(self):
64
        QDialog.reject(self)
클립보드 이미지 추가 (최대 크기: 500 MB)