개정판 617a14d2
fixed some codes
DTI_PID/DTI_PID/DTI_PID.py | ||
---|---|---|
527 | 527 |
sp = sym.getSp() |
528 | 528 |
sw = sym.getWidth() |
529 | 529 |
sh = sym.getHeight() |
530 |
sAngle = sym.getRotatedAngle()
|
|
530 |
angle = sym.getRotatedAngle()
|
|
531 | 531 |
symImg = cv2.imread(path) |
532 |
symImg = cvtGrayImage(symImg)
|
|
532 |
symImg = cv2.threshold(cvtGrayImage(symImg), 127, 255, cv2.THRESH_BINARY)[1]
|
|
533 | 533 |
|
534 |
for i in range(sAngle//90):
|
|
534 |
for i in range(angle//90):
|
|
535 | 535 |
symImg = cv2.rotate(symImg, cv2.ROTATE_90_COUNTERCLOCKWISE) |
536 | 536 |
|
537 | 537 |
threadLock.acquire() |
... | ... | |
539 | 539 |
temp = srcGray[sp[1]:sp[1]+sh, sp[0]:sp[0]+sw] |
540 | 540 |
symImgBin = cv2.bitwise_not(symImg) |
541 | 541 |
result = cv2.bitwise_xor(symImgBin, temp) |
542 |
kernel1 = np.ones((5, 5), np.uint8) |
|
543 |
result = cv2.dilate(result, kernel1) |
|
542 |
result = cv2.dilate(result, np.ones((5, 5), np.uint8)) |
|
544 | 543 |
srcGray[sp[1]:sp[1]+sh, sp[0]:sp[0]+sw] = result |
545 | 544 |
ocrCompletedSrc[sp[1]:sp[1]+sh, sp[0]:sp[0]+sw] = result |
546 | 545 |
threadLock.release() |
... | ... | |
590 | 589 |
chan, w, h = symImg.shape[::-1] |
591 | 590 |
canvas[symbolSp[1]:symbolSp[1]+h, symbolSp[0]:symbolSp[0]+w] = cv2.bitwise_and(canvas[symbolSp[1]:symbolSp[1]+h, symbolSp[0]:symbolSp[0]+w], symImg) |
592 | 591 |
|
593 |
|
|
594 | 592 |
##### Detect text in symbol |
593 |
''' |
|
595 | 594 |
docData = AppDocData.instance() |
596 | 595 |
configs = docData.getConfigs('Text Area', 'Text Area') |
597 | 596 |
value = int(configs[0].value) if 1 == len(configs) else 0 |
... | ... | |
669 | 668 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
670 | 669 |
finally: |
671 | 670 |
threadLock.release() |
671 |
''' |
|
672 | 672 |
|
673 | 673 |
''' |
674 | 674 |
@brief draw found symbols and texts |
... | ... | |
860 | 860 |
humkyung 2018.06.11 add drawing path to parameter and write recognized lines to image |
861 | 861 |
''' |
862 | 862 |
def recognizeLine(path, listWidget, graphicsView): |
863 |
import shapely
|
|
863 |
from shapely.geometry import Point, LineString
|
|
864 | 864 |
from SymbolSvgItem import SymbolSvgItem |
865 | 865 |
from QEngineeringFlowArrowItem import QEngineeringFlowArrowItem |
866 | 866 |
from QEngineeringLineNoTextItem import QEngineeringLineNoTextItem |
... | ... | |
906 | 906 |
|
907 | 907 |
# connect line to line |
908 | 908 |
try: |
909 |
for line in connectedLines[:]:
|
|
909 |
for line in connectedLines: |
|
910 | 910 |
matches = [it for it in connectedLines if (it is not line) and (not detector.isParallel(line, it))] |
911 | 911 |
|
912 | 912 |
# get closest line |
913 |
minDist = None |
|
914 |
selected = None |
|
915 |
shapelyLine = shapely.geometry.LineString(line) |
|
916 |
for it in matches: |
|
917 |
ptStart = it.startPoint() |
|
918 |
dist = line.distance(shapely.geometry.Point(ptStart[0], ptStart[1])) |
|
919 |
if minDist is None or dist < minDist: |
|
920 |
minDist = dist |
|
921 |
selected = it |
|
922 |
ptEnd = it.endPoint() |
|
923 |
dist = line.distance(shapely.geometry.Point(ptEnd[0], ptEnd[1])) |
|
924 |
if minDist is None or dist < minDist: |
|
925 |
minDist = dist |
|
926 |
selected = it |
|
913 |
selected = [] |
|
914 |
shapelyLine = LineString(line) |
|
915 |
for match in matches: |
|
916 |
dist = [shapelyLine.distance(Point(match[0][0], match[0][1])),shapelyLine.distance(Point(match[1][0], match[1][1]))] |
|
917 |
if dist[0] < 20 or dist[1] < 20: |
|
918 |
selected.append(match) |
|
927 | 919 |
# up to here |
928 | 920 |
|
929 |
if selected is not None: |
|
930 |
detector.connectLineToLine(selected, line) |
|
921 |
#if selected is not None and selected[1] < 20: |
|
922 |
# print('{}-{}-{}'.format(line, selected[0], selected[1])) |
|
923 |
for match in selected: |
|
924 |
print('{}-{}-{}'.format(line, match)) |
|
925 |
detector.connectLineToLine(match, line) |
|
931 | 926 |
except Exception as ex: |
932 | 927 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
933 | 928 |
# up to here |
내보내기 Unified diff