프로젝트

일반

사용자정보

개정판 fb3283ea

IDfb3283ea06b3c81f0c68de87b1a6622ed086e9b7
상위 2b47126a
하위 02294b59, f0a78ddf

김정우 이(가) 약 7년 전에 추가함

Area OCR 시 텍스트 회전, 재검출 기능 추가

차이점 보기:

DTI_PID/DTI_PID/Commands/AreaOcrCommand.py
56 56
                                    width = textInfo.getW()
57 57
                                    height = textInfo.getH()
58 58
                                    item = QEngineeringTextItem()
59
                                    item.loc = (x, y)
60
                                    item.size = (width, height)
59 61
                                    item.setPlainText(text)
60 62
                                    item.setDefaultTextColor(Qt.blue)
61 63
                                    sx = 1
DTI_PID/DTI_PID/QOcrResultDialog.py
9 9
import io
10 10
import numpy as np
11 11
import cv2
12
import math
12 13

  
13 14
class QOcrResultDialog(QDialog):
14 15
    def __init__(self, parent, qimage, boundingBox):
......
16 17
        self.image = qimage
17 18
        self.boundingBox = boundingBox
18 19

  
20
        self.angle = 0 # angle is degree
21

  
19 22
        self.ui = UI_OcrResultDialog.Ui_Dialog()
20 23
        self.ui.setupUi(self)
21 24
        
......
29 32
        self.graphicsView.useDefaultCommand() ##### USE DEFAULT COMMAND
30 33
        self.graphicsView.setImage(self.image)
31 34
        self.ui.targetVerticalLayout.addWidget(self.graphicsView)
35
        
36
        self.ui.counterClockPushButton.clicked.connect(lambda : self.rotateImage(True))
37
        self.ui.clockPushButton.clicked.connect(lambda : self.rotateImage(False))
38
        self.ui.redetectPushButton.clicked.connect(self.detectText)
32 39

  
33 40
        self.detectText()
34 41

  
35 42
        self.isAccepted = False
36 43

  
44
    def rotateImage(self, isCounterClock):
45
        for item in self.graphicsView.scene.items():
46
            self.graphicsView.scene.removeItem(item)
47
        self.graphicsView.clearImage()
48
        transform = QTransform()
49
        if isCounterClock:
50
            '''CounterClock'''
51
            self.angle = (self.angle - 90) % 360
52
            transform.rotate(-90)
53
        else:
54
            '''Clock'''
55
            self.angle = (self.angle - 270) % 360
56
            transform.rotate(90)
57
        print(str(360 - self.angle))
58
        self.image = self.image.transformed(transform)
59
        self.graphicsView.setImage(self.image)
60

  
37 61
    def detectText(self):
38 62
        buffer = QBuffer()
39 63
        buffer.open(QBuffer.ReadWrite)
......
62 86
        splitText = text.split('\n')
63 87
        if self.textInfoList is not None and len(self.textInfoList) > 0:
64 88
            for index in range(len(splitText)):
65
                self.textInfoList[index].setText(splitText[index])
89
                textInfo = self.textInfoList[index]
90
                textInfo.setText(splitText[index])
91
                radian = round(math.radians(abs(self.angle)), 2)
92
                textInfo.setAngle(radian) # 360 degree == 6.28319 radian
93
                if radian == 1.57 or radian == 4.71:
94
                    width = textInfo.getW()
95
                    height = textInfo.getH()
96
                    textInfo.setW(height) ## SWAP
97
                    textInfo.setH(width) ## SWAP
66 98
        QDialog.accept(self)
67 99

  
68 100
    def reject(self):
DTI_PID/DTI_PID/UI/OcrResultDialog.py
1
# -*- coding: utf-8 -*-
2

  
3
# Form implementation generated from reading ui file 'OcrResultDialog.ui'
4
#
5
# Created by: PyQt5 UI code generator 5.6
6
#
7
# WARNING! All changes made in this file will be lost!
8

  
9
from PyQt5 import QtCore, QtGui, QtWidgets
10

  
11
class Ui_Dialog(object):
12
    def setupUi(self, Dialog):
13
        Dialog.setObjectName("Dialog")
14
        Dialog.resize(800, 400)
15
        self.ocrDialogButtonBox = QtWidgets.QDialogButtonBox(Dialog)
16
        self.ocrDialogButtonBox.setGeometry(QtCore.QRect(450, 360, 341, 32))
17
        self.ocrDialogButtonBox.setOrientation(QtCore.Qt.Horizontal)
18
        self.ocrDialogButtonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
19
        self.ocrDialogButtonBox.setObjectName("ocrDialogButtonBox")
20
        self.gridLayoutWidget = QtWidgets.QWidget(Dialog)
21
        self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 781, 341))
22
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
23
        self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
24
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
25
        self.gridLayout.setObjectName("gridLayout")
26
        self.widget_2 = QtWidgets.QWidget(self.gridLayoutWidget)
27
        self.widget_2.setObjectName("widget_2")
28
        self.verticalLayoutWidget = QtWidgets.QWidget(self.widget_2)
29
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 761, 151))
30
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
31
        self.detectResultVerticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
32
        self.detectResultVerticalLayout.setContentsMargins(0, 0, 0, 0)
33
        self.detectResultVerticalLayout.setObjectName("detectResultVerticalLayout")
34
        self.detectResultLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
35
        font = QtGui.QFont()
36
        font.setBold(True)
37
        font.setWeight(75)
38
        self.detectResultLabel.setFont(font)
39
        self.detectResultLabel.setObjectName("detectResultLabel")
40
        self.detectResultVerticalLayout.addWidget(self.detectResultLabel)
41
        self.detectResultTextEdit = QtWidgets.QTextEdit(self.verticalLayoutWidget)
42
        self.detectResultTextEdit.setObjectName("detectResultTextEdit")
43
        self.detectResultVerticalLayout.addWidget(self.detectResultTextEdit)
44
        self.gridLayout.addWidget(self.widget_2, 1, 0, 1, 1)
45
        self.widget = QtWidgets.QWidget(self.gridLayoutWidget)
46
        self.widget.setObjectName("widget")
47
        self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.widget)
48
        self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(10, 10, 761, 151))
49
        self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
50
        self.targetVerticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
51
        self.targetVerticalLayout.setContentsMargins(0, 0, 0, 0)
52
        self.targetVerticalLayout.setObjectName("targetVerticalLayout")
53
        self.targetTextLabel = QtWidgets.QLabel(self.verticalLayoutWidget_2)
54
        font = QtGui.QFont()
55
        font.setBold(True)
56
        font.setWeight(75)
57
        self.targetTextLabel.setFont(font)
58
        self.targetTextLabel.setObjectName("targetTextLabel")
59
        self.targetVerticalLayout.addWidget(self.targetTextLabel)
60
        self.gridLayout.addWidget(self.widget, 0, 0, 1, 1)
61

  
62
        self.retranslateUi(Dialog)
63
        self.ocrDialogButtonBox.accepted.connect(Dialog.accept)
64
        self.ocrDialogButtonBox.rejected.connect(Dialog.reject)
65
        QtCore.QMetaObject.connectSlotsByName(Dialog)
66

  
67
    def retranslateUi(self, Dialog):
68
        _translate = QtCore.QCoreApplication.translate
69
        Dialog.setWindowTitle(_translate("Dialog", "OCR"))
70
        self.detectResultLabel.setText(_translate("Dialog", "검출 결과"))
71
        self.targetTextLabel.setText(_translate("Dialog", "검출 대상"))
72

  
73

  
74
if __name__ == "__main__":
75
    import sys
76
    app = QtWidgets.QApplication(sys.argv)
77
    Dialog = QtWidgets.QDialog()
78
    ui = Ui_Dialog()
79
    ui.setupUi(Dialog)
80
    Dialog.show()
81
    sys.exit(app.exec_())
82

  
DTI_PID/DTI_PID/UI/OcrResultDialog.ui
17 17
   <property name="geometry">
18 18
    <rect>
19 19
     <x>450</x>
20
     <y>360</y>
20
     <y>370</y>
21 21
     <width>341</width>
22 22
     <height>32</height>
23 23
    </rect>
......
35 35
     <x>10</x>
36 36
     <y>10</y>
37 37
     <width>781</width>
38
     <height>341</height>
38
     <height>351</height>
39 39
    </rect>
40 40
   </property>
41 41
   <layout class="QGridLayout" name="gridLayout">
......
76 76
      <widget class="QWidget" name="verticalLayoutWidget_2">
77 77
       <property name="geometry">
78 78
        <rect>
79
         <x>10</x>
80
         <y>10</y>
81
         <width>761</width>
82
         <height>151</height>
79
         <x>0</x>
80
         <y>0</y>
81
         <width>781</width>
82
         <height>171</height>
83 83
        </rect>
84 84
       </property>
85
       <layout class="QVBoxLayout" name="targetVerticalLayout">
85
       <layout class="QVBoxLayout" name="tVerticalLayout">
86 86
        <item>
87
         <widget class="QLabel" name="targetTextLabel">
88
          <property name="font">
89
           <font>
90
            <weight>75</weight>
91
            <bold>true</bold>
92
           </font>
93
          </property>
94
          <property name="text">
95
           <string>검출 대상</string>
96
          </property>
87
         <widget class="QWidget" name="targetToolsWidget" native="true">
88
          <widget class="QWidget" name="gridLayoutWidget_2">
89
           <property name="geometry">
90
            <rect>
91
             <x>10</x>
92
             <y>10</y>
93
             <width>761</width>
94
             <height>25</height>
95
            </rect>
96
           </property>
97
           <layout class="QGridLayout" name="gridLayout_2">
98
            <item row="0" column="2">
99
             <widget class="QPushButton" name="clockPushButton">
100
              <property name="text">
101
               <string>Clock</string>
102
              </property>
103
             </widget>
104
            </item>
105
            <item row="0" column="1">
106
             <widget class="QPushButton" name="counterClockPushButton">
107
              <property name="text">
108
               <string>CounterClock</string>
109
              </property>
110
             </widget>
111
            </item>
112
            <item row="0" column="3">
113
             <widget class="QPushButton" name="redetectPushButton">
114
              <property name="text">
115
               <string>Re-Detect</string>
116
              </property>
117
             </widget>
118
            </item>
119
            <item row="0" column="0">
120
             <widget class="QLabel" name="targetTextLabel">
121
              <property name="font">
122
               <font>
123
                <weight>75</weight>
124
                <bold>true</bold>
125
               </font>
126
              </property>
127
              <property name="text">
128
               <string>검출 대상</string>
129
              </property>
130
             </widget>
131
            </item>
132
           </layout>
133
          </widget>
134
          <widget class="QWidget" name="widget_3" native="true">
135
           <property name="geometry">
136
            <rect>
137
             <x>10</x>
138
             <y>40</y>
139
             <width>761</width>
140
             <height>121</height>
141
            </rect>
142
           </property>
143
           <widget class="QWidget" name="verticalLayoutWidget_3">
144
            <property name="geometry">
145
             <rect>
146
              <x>0</x>
147
              <y>0</y>
148
              <width>761</width>
149
              <height>121</height>
150
             </rect>
151
            </property>
152
            <layout class="QVBoxLayout" name="targetVerticalLayout"/>
153
           </widget>
154
          </widget>
97 155
         </widget>
98 156
        </item>
99 157
       </layout>
DTI_PID/DTI_PID/UI_OcrResultDialog.py
13 13
        Dialog.setObjectName("Dialog")
14 14
        Dialog.resize(800, 400)
15 15
        self.ocrDialogButtonBox = QtWidgets.QDialogButtonBox(Dialog)
16
        self.ocrDialogButtonBox.setGeometry(QtCore.QRect(450, 360, 341, 32))
16
        self.ocrDialogButtonBox.setGeometry(QtCore.QRect(450, 370, 341, 32))
17 17
        self.ocrDialogButtonBox.setOrientation(QtCore.Qt.Horizontal)
18 18
        self.ocrDialogButtonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
19 19
        self.ocrDialogButtonBox.setObjectName("ocrDialogButtonBox")
20 20
        self.gridLayoutWidget = QtWidgets.QWidget(Dialog)
21
        self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 781, 341))
21
        self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 781, 351))
22 22
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
23 23
        self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
24 24
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
......
45 45
        self.widget = QtWidgets.QWidget(self.gridLayoutWidget)
46 46
        self.widget.setObjectName("widget")
47 47
        self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.widget)
48
        self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(10, 10, 761, 151))
48
        self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(0, 0, 781, 171))
49 49
        self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
50
        self.targetVerticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
51
        self.targetVerticalLayout.setContentsMargins(0, 0, 0, 0)
52
        self.targetVerticalLayout.setObjectName("targetVerticalLayout")
53
        self.targetTextLabel = QtWidgets.QLabel(self.verticalLayoutWidget_2)
50
        self.tVerticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
51
        self.tVerticalLayout.setContentsMargins(0, 0, 0, 0)
52
        self.tVerticalLayout.setObjectName("tVerticalLayout")
53
        self.targetToolsWidget = QtWidgets.QWidget(self.verticalLayoutWidget_2)
54
        self.targetToolsWidget.setObjectName("targetToolsWidget")
55
        self.gridLayoutWidget_2 = QtWidgets.QWidget(self.targetToolsWidget)
56
        self.gridLayoutWidget_2.setGeometry(QtCore.QRect(10, 10, 761, 25))
57
        self.gridLayoutWidget_2.setObjectName("gridLayoutWidget_2")
58
        self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget_2)
59
        self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
60
        self.gridLayout_2.setObjectName("gridLayout_2")
61
        self.clockPushButton = QtWidgets.QPushButton(self.gridLayoutWidget_2)
62
        self.clockPushButton.setObjectName("clockPushButton")
63
        self.gridLayout_2.addWidget(self.clockPushButton, 0, 2, 1, 1)
64
        self.counterClockPushButton = QtWidgets.QPushButton(self.gridLayoutWidget_2)
65
        self.counterClockPushButton.setObjectName("counterClockPushButton")
66
        self.gridLayout_2.addWidget(self.counterClockPushButton, 0, 1, 1, 1)
67
        self.redetectPushButton = QtWidgets.QPushButton(self.gridLayoutWidget_2)
68
        self.redetectPushButton.setObjectName("redetectPushButton")
69
        self.gridLayout_2.addWidget(self.redetectPushButton, 0, 3, 1, 1)
70
        self.targetTextLabel = QtWidgets.QLabel(self.gridLayoutWidget_2)
54 71
        font = QtGui.QFont()
55 72
        font.setBold(True)
56 73
        font.setWeight(75)
57 74
        self.targetTextLabel.setFont(font)
58 75
        self.targetTextLabel.setObjectName("targetTextLabel")
59
        self.targetVerticalLayout.addWidget(self.targetTextLabel)
76
        self.gridLayout_2.addWidget(self.targetTextLabel, 0, 0, 1, 1)
77
        self.widget_3 = QtWidgets.QWidget(self.targetToolsWidget)
78
        self.widget_3.setGeometry(QtCore.QRect(10, 40, 761, 121))
79
        self.widget_3.setObjectName("widget_3")
80
        self.verticalLayoutWidget_3 = QtWidgets.QWidget(self.widget_3)
81
        self.verticalLayoutWidget_3.setGeometry(QtCore.QRect(0, 0, 761, 121))
82
        self.verticalLayoutWidget_3.setObjectName("verticalLayoutWidget_3")
83
        self.targetVerticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_3)
84
        self.targetVerticalLayout.setContentsMargins(0, 0, 0, 0)
85
        self.targetVerticalLayout.setObjectName("targetVerticalLayout")
86
        self.tVerticalLayout.addWidget(self.targetToolsWidget)
60 87
        self.gridLayout.addWidget(self.widget, 0, 0, 1, 1)
61 88

  
62 89
        self.retranslateUi(Dialog)
......
68 95
        _translate = QtCore.QCoreApplication.translate
69 96
        Dialog.setWindowTitle(_translate("Dialog", "OCR"))
70 97
        self.detectResultLabel.setText(_translate("Dialog", "검출 결과"))
98
        self.clockPushButton.setText(_translate("Dialog", "Clock"))
99
        self.counterClockPushButton.setText(_translate("Dialog", "CounterClock"))
100
        self.redetectPushButton.setText(_translate("Dialog", "Re-Detect"))
71 101
        self.targetTextLabel.setText(_translate("Dialog", "검출 대상"))
72 102

  
73 103

  

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)