프로젝트

일반

사용자정보

개정판 528bc774

ID528bc77477a201f59b75c73901c87b6fbb0a00b6
상위 8a899974
하위 02ed19e4, 77ba1662, 0b9c2fba

humkyung 이(가) 약 7년 전에 추가함

Detect line in drawing area

차이점 보기:

DTI_PID/DTI_PID/LineDetector.py
135 135
    def __init__(self, image):
136 136
        thresh = 127
137 137
        self.image = cv2.threshold(image, thresh, 255, cv2.THRESH_BINARY)[1]
138
        depth, self.width, self.height = self.image.shape[::-1]
138
        self.width, self.height = self.image.shape[::-1]
139 139
        self.Result = np.zeros((self.width, self.height, 3), np.uint8)
140 140

  
141 141
    '''
142 142
        @brief symbol을 기준으로 양쪽으로 이미지에서 직선을 검출한다.
143
        @author humkyung
144
        @date   2018.04.??
143 145
    '''
144
    def Detect(self, symbol):
146
    def Detect(self, symbol, offsetX, offsetY):
145 147
        res = []
146 148

  
147 149
        try:
......
150 152
                right = int(symbol.rect().right())
151 153
                left = int(symbol.rect().left())
152 154

  
153
                pt = [right, int(symbol.center.y())]
155
                pt = [right - offsetX, int(symbol.center.y()) - offsetY]
154 156
                pool.append([[1,0], pt])
155
                pt = [left, int(symbol.center.y())]
157
                pt = [left - offsetX, int(symbol.center.y()) - offsetY]
156 158
                pool.append([[-1,0], pt])
157 159
            elif (1.57 == symbol.angle) or (4.71 == symbol.angle):  # rotated by 90 or 270 degree
158 160
                bottom = int(symbol.rect().bottom())
159 161
                top = int(symbol.rect().top())
160 162

  
161
                pt = [int(symbol.center.x()), bottom]
163
                pt = [int(symbol.center.x()) - offsetX, bottom - offsetY]
162 164
                pool.append([[0,1], pt])
163
                pt = [int(symbol.center.x()), top]
165
                pt = [int(symbol.center.x()) - offsetX, top - offsetY]
164 166
                pool.append([[0,-1], pt])
165 167

  
166 168
            while len(pool) > 0:
......
189 191
    def detectLine(self, pt, dir):
190 192
        from AppDocData import AppDocData
191 193

  
192
        white = [255,255,255]
194
        white = [255]
193 195
        windowSize = AppDocData.instance().getSlidingWindowSize()
194 196
        xHalf = int(windowSize[0]*0.5)
195 197
        yHalf = int(windowSize[1]*0.5)
196 198

  
197 199
        if ([1,0] == dir):
198 200
            image = self.image[(pt[1]-yHalf):(pt[1]+yHalf), pt[0]:self.width]
199
            imgDepth, imgWidth, imgHeight = image.shape[::-1]
201
            imgWidth, imgHeight = image.shape[::-1]
200 202
            for i in range(imgWidth-windowSize[0]):
201 203
                window = image[0:windowSize[1], i:i+windowSize[0]]
202 204
                if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break
......
205 207
                return [(pt[0], pt[1]), (pt[0] + i, pt[1])]
206 208
        elif ([-1,0] == dir):
207 209
            image = self.image[(pt[1]-yHalf):(pt[1]+yHalf), 0:pt[0]]
208
            imgDepth, imgWidth, imgHeight = image.shape[::-1]
210
            imgWidth, imgHeight = image.shape[::-1]
209 211
            for i in range(imgWidth-windowSize[0], -1, -1):
210 212
                window = image[0:windowSize[1], i:i+windowSize[0]]
211 213
                if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break
......
218 220
            yHalf = int(windowSize[1]*0.5)
219 221

  
220 222
            image = self.image[pt[1]:self.height, int(pt[0]-xHalf):int(pt[0]+xHalf)]
221
            imgDepth, imgWidth, imgHeight = image.shape[::-1]
223
            imgWidth, imgHeight = image.shape[::-1]
222 224
            for i in range(imgHeight-windowSize[1]):
223 225
                window = image[i:i+windowSize[1], 0:windowSize[0]]
224 226
                if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break
......
231 233
            yHalf = int(windowSize[1]*0.5)
232 234

  
233 235
            image = self.image[0:pt[1], int(pt[0]-xHalf):int(pt[0]+xHalf)]
234
            imgDepth, imgWidth, imgHeight = image.shape[::-1]
236
            imgWidth, imgHeight = image.shape[::-1]
235 237
            for i in range(imgHeight-windowSize[1], -1, -1):
236 238
                window = image[i:i+windowSize[1], 0:windowSize[0]]
237 239
                if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break

내보내기 Unified diff