프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / SymbolThicknessDialog.py @ 3a6c46a5

이력 | 보기 | 이력해설 | 다운로드 (2.32 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
            try:
31
                project = AppDocData.instance().getCurrentProject()
32
                rootPath = project.getImageFilePath()
33
                rootList = os.listdir(rootPath)
34

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

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

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

    
48
                        e = cv2.erode(new, kernel, iterations=1)
49
                        cv2.imwrite(fullPath, e)
50

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

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

    
59
        QDialog.accept(self)
60

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