개정판 4841dcf8
fixed issue #480:
- 심볼에서 떨어진 라인을 인식하는 오류
DTI_PID/DTI_PID/LineDetector.py | ||
---|---|---|
170 | 170 |
return res |
171 | 171 | |
172 | 172 |
''' |
173 |
@brief adjust start point |
|
174 |
@author humkyung |
|
175 |
@date 2018.06.21 |
|
173 |
@brief adjust start point |
|
174 |
@author humkyung |
|
175 |
@date 2018.06.21 |
|
176 |
@history humkyung 2018.07.31 return -1 thickness tuple if near point is not black |
|
176 | 177 |
''' |
177 | 178 |
def adjustStartPoint(self, pt, dir): |
178 |
import math |
|
179 | 179 |
from AppDocData import AppDocData |
180 | 180 |
docData = AppDocData.instance() |
181 | 181 |
windowSize = docData.getSlidingWindowSize() |
... | ... | |
187 | 187 |
if black == self._image[pt[1] + round(dir[1]*windowSize[1]), pt[0] + round(dir[0]*windowSize[1])]: |
188 | 188 |
_pt = [pt[0] + round(dir[0]*windowSize[1]), pt[1] + round(dir[1]*windowSize[1])] |
189 | 189 |
else: |
190 |
return (pt, windowSize[1])
|
|
190 |
return (pt, -1)
|
|
191 | 191 | |
192 | 192 |
norm = [-dir[1], dir[0]] |
193 | 193 | |
... | ... | |
239 | 239 |
dx /= length |
240 | 240 |
dy /= length |
241 | 241 | |
242 |
if abs(dx) < 0.1: |
|
242 |
if abs(dx) < 0.1: # vertical line
|
|
243 | 243 |
dir = [0,1 if dy > 0 else -1] |
244 | 244 |
pt = [round(conn[0] - offsetX), round(conn[1] - offsetY)] |
245 | 245 |
pt, thickness = self.adjustStartPoint(pt, dir) |
246 |
pool.append([dir, pt, thickness]) |
|
247 |
elif abs(dy) < 0.1: |
|
246 |
if thickness != -1: pool.append([dir, pt, thickness])
|
|
247 |
elif abs(dy) < 0.1: # horizontal line
|
|
248 | 248 |
dir = [1 if dx > 0 else -1,0] |
249 | 249 |
pt = [round(conn[0] - offsetX), round(conn[1] - offsetY)] |
250 | 250 |
pt, thickness = self.adjustStartPoint(pt, dir) |
251 |
pool.append([dir, pt, thickness]) |
|
251 |
if thickness != -1: pool.append([dir, pt, thickness])
|
|
252 | 252 | |
253 | 253 |
while len(pool) > 0: |
254 | 254 |
dir, pt, thickness = pool.pop() |
... | ... | |
258 | 258 |
if ([1,0] == dir) or ([-1,0] == dir): # turn up/down |
259 | 259 |
connectedPt = [line[1][0], pt[1]] |
260 | 260 |
pt, thickness = self.adjustStartPoint(connectedPt, [0,1]) |
261 |
pool.append([[0,1], pt, thickness]) |
|
261 |
if thickness != -1: pool.append([[0,1], pt, thickness])
|
|
262 | 262 |
pt, thickness = self.adjustStartPoint(connectedPt, [0,-1]) |
263 |
pool.append([[0,-1], pt, thickness]) |
|
263 |
if thickness != -1: pool.append([[0,-1], pt, thickness])
|
|
264 | 264 |
elif ([0,1] == dir) or ([0,-1] == dir): # turn left/right |
265 | 265 |
connectedPt = [pt[0], line[1][1]] |
266 | 266 |
pt, thickness = self.adjustStartPoint(connectedPt, [1,0]) |
267 |
pool.append([[1,0], pt, thickness]) |
|
267 |
if thickness != -1: pool.append([[1,0], pt, thickness])
|
|
268 | 268 |
pt, thickness = self.adjustStartPoint(connectedPt, [-1,0]) |
269 |
pool.append([[-1,0], pt, thickness]) |
|
269 |
if thickness != -1: pool.append([[-1,0], pt, thickness])
|
|
270 | 270 |
return res |
271 | 271 |
except Exception as ex: |
272 | 272 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
내보내기 Unified diff