개정판 c891ebf3
dev issue #507 : detect opc
Change-Id: I2c5c62a25fd59255bee3928b876f0c98684c6c1c
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
935 | 935 |
sh, sow, soh) |
936 | 936 |
|
937 | 937 |
# For OPC |
938 |
drawing_area = app_doc_data.getArea('Drawing') |
|
939 |
if drawing_area is not None and (symbolType == "Piping OPC\'s" or symbolType == "Instrument OPC\'s"): |
|
940 |
worker.detectOPCOnPid(drawing_area, symGray) |
|
938 |
# drawing_area = app_doc_data.getArea('Drawing') |
|
939 |
# if drawing_area is not None and (symbolType == "Piping OPC\'s" or symbolType == "Instrument OPC\'s"): |
|
940 |
# customMatch = worker.detectOPCOnPid(drawing_area, symGray) |
|
941 |
# if customMatch and len(customMatch) > 0: |
|
942 |
# for custom in customMatch: |
|
943 |
# hitRate = custom[0] |
|
944 |
# searchedItemSp = ( |
|
945 |
# custom[1][0] + round(offsetDrawingArea[0]), custom[1][1] + round(offsetDrawingArea[1])) |
|
946 |
# |
|
947 |
# is_add = True |
|
948 |
# for searched in searchedSymbolList: |
|
949 |
# if Worker.IsOverlap((searchedItemSp[0], searchedItemSp[1], sw, sh), ( |
|
950 |
# searched.getSp()[0], searched.getSp()[1], searched.getWidth(), |
|
951 |
# searched.getHeight())): |
|
952 |
# if searched.getHitRate() > hitRate: |
|
953 |
# is_add = False |
|
954 |
# else: |
|
955 |
# searchedSymbolList.remove(searched) |
|
956 |
# break |
|
957 |
# |
|
958 |
# if is_add: |
|
959 |
# threadLock.acquire() |
|
960 |
# foundSymbolCount = foundSymbolCount + 1 |
|
961 |
# Worker.addSearchedSymbol(symbolName, symbolType, |
|
962 |
# searchedItemSp, sw, sh, symbolThreshold, symbolMinMatchCount, |
|
963 |
# hitRate, symbolRotatedAngle, |
|
964 |
# isDetectOnOrigin, symbolRotateCount, symbolOcrOption, |
|
965 |
# isContainChild, |
|
966 |
# originalPoint, connectionPoint, baseSymbol, additionalSymbol, |
|
967 |
# isExceptDetect, detectFlip=1 if index is 1 else 0, |
|
968 |
# hasInstrumentLabel=hasInstrumentLabel) |
|
969 |
# threadLock.release() |
|
941 | 970 |
|
942 | 971 |
# Template Matching |
943 | 972 |
tmRes = cv2.matchTemplate(roiItem, symGray, cv2.TM_CCOEFF_NORMED) |
... | ... | |
1107 | 1136 |
return [] |
1108 | 1137 |
|
1109 | 1138 |
@staticmethod |
1139 |
def IsOverlap(range1, range2): |
|
1140 |
if range1[0] <= range2[0] + range2[2] and range1[0] + range1[2] >= range2[0] and range1[1] <= range2[1] + \ |
|
1141 |
range2[3] and range1[1] + range1[3] >= range2[1]: |
|
1142 |
range = (min(range1[0] + range1[2], range2[0] + range2[2]) - max(range1[0], range2[0])) * ( |
|
1143 |
min(range1[1] + range1[3], range2[1] + range2[3]) - max(range1[1], range2[1])) |
|
1144 |
if range >= range1[2] * range1[3] * 0.4 and range >= range2[2] * range2[3] * 0.4: |
|
1145 |
return True |
|
1146 |
else: |
|
1147 |
return False |
|
1148 |
else: |
|
1149 |
return False |
|
1150 |
|
|
1151 |
@staticmethod |
|
1110 | 1152 |
def detectOPCOnPid(area, symGray): |
1111 | 1153 |
results = [] |
1112 | 1154 |
|
1113 |
# try: |
|
1114 |
# symbol = cv2.copyMakeBorder(symGray, 1, 1, 1, 1, cv2.BORDER_CONSTANT, value=255) |
|
1115 |
# not_symbol = cv2.bitwise_not(symbol) |
|
1116 |
# symbol_contours, symbol_hierachy = cv2.findContours(not_symbol, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
|
1117 |
# if symbol_hierachy[0][0][0] != -1: |
|
1118 |
# return results |
|
1119 |
# |
|
1120 |
# contour_count = len(symbol_contours) |
|
1121 |
# for i in range(1, contour_count): |
|
1122 |
# symbol_area = cv2.contourArea(symbol_contours[i]) |
|
1123 |
# |
|
1124 |
# for contour in area.contours: |
|
1125 |
# area_area = cv2.contourArea(contour) |
|
1126 |
# if area_area * 1.2 >= symbol_area >= area_area * 0.8: |
|
1127 |
# I1 = cv2.matchShapes(symbol_contours[i], contour, 1, 0) |
|
1128 |
# I2 = cv2.matchShapes(symbol_contours[i], contour, 2, 0) |
|
1129 |
# I3 = cv2.matchShapes(symbol_contours[i], contour, 3, 0) |
|
1130 |
# if I1 < 1 and I2 < 1 and I3 < 0.1: |
|
1131 |
# rect = cv2.boundingRect(contour) |
|
1132 |
# results.append([0.8, [rect[0],rect[1]]]) |
|
1133 |
# break |
|
1134 |
# except Exception as ex: |
|
1135 |
# message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
1136 |
# sys.exc_info()[-1].tb_lineno) |
|
1137 |
# a = 5 |
|
1138 |
|
|
1155 |
try: |
|
1156 |
symbol = cv2.copyMakeBorder(symGray, 1, 1, 1, 1, cv2.BORDER_CONSTANT, value=255) |
|
1157 |
not_symbol = cv2.bitwise_not(symbol) |
|
1158 |
symbol_contours, symbol_hierachy = cv2.findContours(not_symbol, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
|
1159 |
if symbol_hierachy[0][0][0] != -1: |
|
1160 |
return results |
|
1161 |
|
|
1162 |
contour_count = len(symbol_contours) |
|
1163 |
for i in range(1, contour_count): |
|
1164 |
symbol_area = cv2.contourArea(symbol_contours[i]) |
|
1165 |
|
|
1166 |
for contour in area.contours: |
|
1167 |
area_area = cv2.contourArea(contour) |
|
1168 |
if area_area * 1.2 >= symbol_area >= area_area * 0.8: |
|
1169 |
I1 = cv2.matchShapes(symbol_contours[i], contour, 1, 0) |
|
1170 |
I2 = cv2.matchShapes(symbol_contours[i], contour, 2, 0) |
|
1171 |
I3 = cv2.matchShapes(symbol_contours[i], contour, 3, 0) |
|
1172 |
if I1 < 1 and I2 < 1 and I3 < 0.1: |
|
1173 |
|
|
1174 |
rect = cv2.boundingRect(contour) |
|
1175 |
results.append([1 - I3, [rect[0], rect[1]]]) |
|
1176 |
break |
|
1177 |
except Exception as ex: |
|
1178 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
1179 |
sys.exc_info()[-1].tb_lineno) |
|
1139 | 1180 |
return results |
1140 | 1181 |
|
1141 | 1182 |
''' |
1142 |
@brief detect nozzle |
|
1183 |
@brief detect nozzlez
|
|
1143 | 1184 |
@author humkyung |
1144 | 1185 |
@date 2018.07.07 |
1145 | 1186 |
@history humkyhung 2018.07.17 pass equpment as parameter instead of image |
내보내기 Unified diff