7 |
7 |
from PyQt5.QtCore import *
|
8 |
8 |
from PyQt5.QtGui import *
|
9 |
9 |
from PyQt5.QtWidgets import *
|
|
10 |
from AppDocData import AppDocData
|
10 |
11 |
|
11 |
12 |
__author__ = "humkyung <humkyung.doftech.co.kr>"
|
12 |
13 |
__version__ = '1.0.0'
|
... | ... | |
247 |
248 |
"""adjust start point of line and then return start point and thickness of line
|
248 |
249 |
return -1 for thickness if fail to calculate thickness
|
249 |
250 |
"""
|
250 |
|
from AppDocData import AppDocData
|
251 |
251 |
|
252 |
252 |
app_doc_data = AppDocData.instance()
|
253 |
253 |
windowSize = app_doc_data.getSlidingWindowSize()
|
... | ... | |
314 |
314 |
humkyung 2018.04.12 use connection points without rotating(already rotated)
|
315 |
315 |
humkyung 2018.09.01 use connector's direction for detecting line
|
316 |
316 |
'''
|
317 |
|
|
318 |
317 |
def detectConnectedLine(self, symbol, offsetX, offsetY):
|
319 |
318 |
res = []
|
320 |
319 |
|
... | ... | |
384 |
383 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
385 |
384 |
sys.exc_info()[-1].tb_lineno)
|
386 |
385 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
|
386 |
|
|
387 |
def correct_angle(self, lines):
|
|
388 |
""" fix angle """
|
|
389 |
from HoughBundler import HoughBundler
|
|
390 |
|
|
391 |
app_doc_data = AppDocData.instance()
|
|
392 |
configs = app_doc_data.getConfigs('Line', 'Diagonal')
|
|
393 |
diagonal = HoughBundler()
|
|
394 |
for index in reversed(range(len(lines))):
|
|
395 |
line = lines[index]
|
|
396 |
angle = diagonal.get_orientation([line[0][0], line[0][1], line[1][0], line[1][1]])
|
|
397 |
if not (angle < 3 or angle > 87):
|
|
398 |
if configs and int(configs[0].value) is not 1:
|
|
399 |
lines.pop(index)
|
|
400 |
elif angle < 3 and angle > 0:
|
|
401 |
new_x = int((line[0][0] + line[1][0]) / 2)
|
|
402 |
line[0][0], line[1][0] = new_x, new_x
|
|
403 |
elif angle > 87 and angle < 90:
|
|
404 |
new_y = int((line[0][1] + line[1][1]) / 2)
|
|
405 |
line[0][1], line[1][1] = new_y, new_y
|
387 |
406 |
|
388 |
407 |
def mergeLines(self, connectedLines, toler=20, symbol_areas=None):
|
389 |
408 |
"""merge lines(1.connect collinear lines 2.connect lines)"""
|
... | ... | |
413 |
432 |
for match in matches:
|
414 |
433 |
connectedLines.remove(match)
|
415 |
434 |
# up to here
|
|
435 |
|
|
436 |
self.correct_angle(connectedLines)
|
|
437 |
|
|
438 |
# remove overlap line
|
|
439 |
#for long_line in sorted(connectedLines, key=lambda param: param.length(), reverse=True):
|
|
440 |
# for short_line in sorted(connectedLines, key=lambda param: param.length()):
|
|
441 |
# pass
|
|
442 |
# up to here
|
416 |
443 |
except Exception as ex:
|
417 |
444 |
from App import App
|
418 |
445 |
from AppDocData import MessageType
|
... | ... | |
575 |
602 |
'''
|
576 |
603 |
|
577 |
604 |
def detectLineThickness(self, pt, dir):
|
578 |
|
import math
|
579 |
|
from AppDocData import AppDocData
|
580 |
605 |
docData = AppDocData.instance()
|
581 |
606 |
windowSize = docData.getSlidingWindowSize()
|
582 |
607 |
|
... | ... | |
588 |
613 |
if black == self._image[pt[1] + round(dir[1] * windowSize[1]), pt[0] + round(dir[0] * windowSize[1])]:
|
589 |
614 |
_pt = [pt[0] + round(dir[0] * windowSize[1]), pt[1] + round(dir[1] * windowSize[1])]
|
590 |
615 |
else:
|
591 |
|
return windowSize[1]
|
|
616 |
return int(windowSize[1] / 2)
|
592 |
617 |
|
593 |
618 |
color = black
|
594 |
619 |
lhs = [pt[0], pt[1]]
|
... | ... | |
614 |
639 |
|
615 |
640 |
def detectLine(self, pt, dir, thickness, forward):
|
616 |
641 |
"""detect a line along given direction"""
|
617 |
|
from AppDocData import AppDocData
|
618 |
642 |
|
619 |
643 |
app_doc_data = AppDocData.instance()
|
620 |
644 |
lineLengthConfigs = app_doc_data.getConfigs('Small Line Minimum Length', 'Min Length')
|
... | ... | |
695 |
719 |
"""detect remain line after detecting symbol"""
|
696 |
720 |
|
697 |
721 |
import os
|
698 |
|
from AppDocData import AppDocData
|
699 |
722 |
from HoughBundler import HoughBundler
|
700 |
723 |
|
701 |
724 |
app_doc_data = AppDocData.instance()
|
... | ... | |
734 |
757 |
houghBundler = HoughBundler().process_lines(lines, None)
|
735 |
758 |
|
736 |
759 |
remainLines = []
|
|
760 |
configs = app_doc_data.getConfigs('Flow Mark', 'Length')
|
|
761 |
min_length = int(configs[0].value) if 1 == len(configs) else 200
|
|
762 |
|
737 |
763 |
for line in houghBundler:
|
738 |
|
remainLines.append([[line[0][0], line[0][1]], [line[1][0], line[1][1]]])
|
|
764 |
dx = line[0][0] - line[1][0]
|
|
765 |
dy = line[1][0] - line[1][1]
|
|
766 |
length = math.sqrt(dx * dx + dy * dy)
|
|
767 |
|
|
768 |
if length > min_length:
|
|
769 |
remainLines.append([[line[0][0], line[0][1]], [line[1][0], line[1][1]]])
|
739 |
770 |
|
740 |
771 |
# border line check
|
741 |
772 |
borderRate = 0.07
|
... | ... | |
753 |
784 |
self._image.shape[0] - borderY:
|
754 |
785 |
remainLines.pop(index)
|
755 |
786 |
|
|
787 |
self.correct_angle(remainLines)
|
|
788 |
|
756 |
789 |
return remainLines
|
757 |
790 |
|
758 |
791 |
'''
|
... | ... | |
763 |
796 |
|
764 |
797 |
def saveImage(self):
|
765 |
798 |
import datetime
|
766 |
|
from AppDocData import AppDocData
|
767 |
799 |
|
768 |
800 |
try:
|
769 |
801 |
nowDate = datetime.datetime.now()
|