개정판 8b804ab7
issue #103: symbol text area testing
Change-Id: Ie3a2206dc9e5e54eb2157302b33df735885533a8
DTI_PID/DTI_PID/Area.py | ||
---|---|---|
17 | 17 |
self.y = None |
18 | 18 |
self.width = None |
19 | 19 |
self.height = None |
20 |
|
|
21 |
def center(self): |
|
22 |
return (round(self.x + self.width / 2), round(self.y + self.height / 2)) |
|
20 | 23 |
|
21 | 24 |
''' |
22 | 25 |
@brief getter of name |
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
448 | 448 |
titleBlockTextInfoList = None |
449 | 449 |
textInfoList = [] |
450 | 450 |
if worker.isTextChecked: |
451 |
from TextInfo import TextInfo |
|
452 |
|
|
451 | 453 |
textAreas, ocr_image = textDetector.detectTextAreas(area.img if area is not None else app_doc_data.imgSrc, |
452 | 454 |
offset) |
455 |
|
|
456 |
# get text area by using symbol setting |
|
457 |
text_area_symbols = [] |
|
458 |
for symbol in [symbol for symbol in searchedSymbolList if symbol.text_area]: |
|
459 |
for text_area in symbol.text_area: |
|
460 |
so = [symbol.getWidth(), symbol.getHeight()] if symbol.getRotatedAngle() is 0 or symbol.getRotatedAngle() is 180\ |
|
461 |
else [symbol.getHeight(), symbol.getWidth()] |
|
462 |
text_area_origin = Worker.getCalculatedOriginalPoint(None, str(text_area.center()[0]) + ',' + str(text_area.center()[1]),\ |
|
463 |
symbol.getRotatedAngle(), None, None, so[0], so[1], symbol.getDetectFlip()) |
|
464 |
x = text_area_origin[0] - round(text_area.width / 2) if symbol.getRotatedAngle() is 0 or symbol.getRotatedAngle() is 180\ |
|
465 |
else text_area_origin[0] - round(text_area.height / 2) |
|
466 |
x = x + symbol.sp[0] |
|
467 |
y = text_area_origin[1] - round(text_area.height / 2) if symbol.getRotatedAngle() is 0 or symbol.getRotatedAngle() is 180\ |
|
468 |
else text_area_origin[1] - round(text_area.width / 2) |
|
469 |
y = y + symbol.sp[1] |
|
470 |
w = text_area.width if symbol.getRotatedAngle() is 0 or symbol.getRotatedAngle() is 180 else text_area.height |
|
471 |
h = text_area.height if symbol.getRotatedAngle() is 0 or symbol.getRotatedAngle() is 180 else text_area.width |
|
472 |
text_area_symbols.append(TextInfo('', x, y, w, h, symbol.getRotatedAngle())) |
|
473 |
|
|
474 |
for textArea_index in reversed(range(len(textAreas))): |
|
475 |
for text_area_index in reversed(range(len(text_area_symbols))): |
|
476 |
if text_area_symbols[text_area_index].contains(textAreas[textArea_index].center) or \ |
|
477 |
textAreas[textArea_index].contains(text_area_symbols[text_area_index].center): |
|
478 |
if text_area_symbols[text_area_index].area > textAreas[textArea_index].area: |
|
479 |
textAreas.pop(textArea_index) |
|
480 |
else: |
|
481 |
text_area_symbols.pop(text_area_index) |
|
482 |
textAreas.extend(text_area_symbols) |
|
483 |
# up to here |
|
484 |
|
|
453 | 485 |
if maxProgressValue < 2 * len(textAreas): |
454 | 486 |
for _ in range(len(textAreas) - int(maxProgressValue * 0.5)): |
455 | 487 |
worker.updateProgress.emit(2 * len(textAreas), None) |
... | ... | |
800 | 832 |
isExceptDetect = targetSymbol.getIsExceptDetect() |
801 | 833 |
detectFlip = targetSymbol.getDetectFlip() |
802 | 834 |
hasInstrumentLabel = targetSymbol.getHasInstrumentLabel() |
835 |
text_area = targetSymbol.getText_area() |
|
803 | 836 |
|
804 | 837 |
# check if symbol file is target or not |
805 | 838 |
if isExceptDetect == 1: |
... | ... | |
977 | 1010 |
originalPoint, connectionPoint, baseSymbol, additionalSymbol, |
978 | 1011 |
isExceptDetect, |
979 | 1012 |
detectFlip=1 if flipped else 0, |
980 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1013 |
hasInstrumentLabel=hasInstrumentLabel, text_area=text_area)
|
|
981 | 1014 |
threadLock.release() |
982 | 1015 |
else: # 겹치는 영역이 기준값보다 클 경우 |
983 | 1016 |
if symbolIndex != -1 and symbolIndex < len(searchedSymbolList): |
... | ... | |
1006 | 1039 |
baseSymbol, additionalSymbol, |
1007 | 1040 |
isExceptDetect, |
1008 | 1041 |
detectFlip=1 if flipped else 0, |
1009 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1042 |
hasInstrumentLabel=hasInstrumentLabel, text_area=text_area)
|
|
1010 | 1043 |
threadLock.release() |
1011 | 1044 |
# 현재 심볼과 검출된 심볼이 같지 않을 경우 (포함) |
1012 | 1045 |
elif app_doc_data.isEquipmentType(searchedSymbol.getType()): |
... | ... | |
1021 | 1054 |
originalPoint, connectionPoint, baseSymbol, |
1022 | 1055 |
additionalSymbol, isExceptDetect, |
1023 | 1056 |
detectFlip=1 if flipped else 0, |
1024 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1057 |
hasInstrumentLabel=hasInstrumentLabel, text_area=text_area)
|
|
1025 | 1058 |
threadLock.release() |
1026 | 1059 |
# 현재 심볼과 검출된 심볼이 같지 않을 경우 (교체) |
1027 | 1060 |
elif not forTraining: |
... | ... | |
1047 | 1080 |
baseSymbol, additionalSymbol, |
1048 | 1081 |
isExceptDetect, |
1049 | 1082 |
detectFlip=1 if flipped else 0, |
1050 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1083 |
hasInstrumentLabel=hasInstrumentLabel, text_area=text_area)
|
|
1051 | 1084 |
threadLock.release() |
1052 | 1085 |
# 학습용 데이터 생성을 위해 교체하지 않고 추가함 |
1053 | 1086 |
elif forTraining: |
... | ... | |
1061 | 1094 |
originalPoint, connectionPoint, baseSymbol, |
1062 | 1095 |
additionalSymbol, isExceptDetect, |
1063 | 1096 |
detectFlip=1 if flipped else 0, |
1064 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1097 |
hasInstrumentLabel=hasInstrumentLabel, text_area=text_area)
|
|
1065 | 1098 |
threadLock.release() |
1066 | 1099 |
|
1067 | 1100 |
# Rotate Symbol |
... | ... | |
1166 | 1199 |
baseSymbol = nozzle.getBaseSymbol() |
1167 | 1200 |
additionalSymbol = nozzle.getAdditionalSymbol() |
1168 | 1201 |
isExceptDetect = nozzle.getIsExceptDetect() |
1202 |
text_area = text_area |
|
1169 | 1203 |
|
1170 | 1204 |
foundSymbolCount = 0 |
1171 | 1205 |
|
... | ... | |
1268 | 1302 |
, isDetectOnOrigin, symbolRotateCount, symbolOcrOption, |
1269 | 1303 |
isContainChild |
1270 | 1304 |
, originalPoint, connectionPoint, baseSymbol, |
1271 |
additionalSymbol, isExceptDetect) |
|
1305 |
additionalSymbol, isExceptDetect, text_area)
|
|
1272 | 1306 |
searched.owner = equipment |
1273 | 1307 |
threadLock.release() |
1274 | 1308 |
## 겹치는 영역이 기준값보다 클 경우 |
... | ... | |
1290 | 1324 |
'{},{},{},{}'.format(param[0], param[1], |
1291 | 1325 |
param[2], param[3]) |
1292 | 1326 |
for param in connectionPoint), |
1293 |
baseSymbol, additionalSymbol, isExceptDetect) |
|
1327 |
baseSymbol, additionalSymbol, isExceptDetect, text_area)
|
|
1294 | 1328 |
threadLock.release() |
1295 | 1329 |
## 현재 심볼과 검출된 심볼이 같지 않을 경우 (포함) |
1296 | 1330 |
elif appDocData.isEquipmentType(searchedSymbol.getType()): |
... | ... | |
1302 | 1336 |
, isDetectOnOrigin, symbolRotateCount, |
1303 | 1337 |
symbolOcrOption, isContainChild |
1304 | 1338 |
, originalPoint, connectionPoint, baseSymbol, |
1305 |
additionalSymbol, isExceptDetect) |
|
1339 |
additionalSymbol, isExceptDetect, text_area)
|
|
1306 | 1340 |
searched.owner = equipment |
1307 | 1341 |
threadLock.release() |
1308 | 1342 |
|
... | ... | |
1469 | 1503 |
, sp, w, h, threshold, minMatchCount, hitRate, rotatedAngle |
1470 | 1504 |
, isDetectOnOrigin, rotateCount, ocrOption, isContainChild |
1471 | 1505 |
, originalPoint, connectionPoint, baseSymbol, additionalSymbol, isExceptDetect, detectFlip |
1472 |
, hasInstrumentLabel): |
|
1506 |
, hasInstrumentLabel, text_area):
|
|
1473 | 1507 |
global searchedSymbolList |
1474 | 1508 |
|
1475 | 1509 |
newSym = None |
... | ... | |
1481 | 1515 |
'/'.join('{},{},{},{}'.format(param[0], param[1], param[2], param[3]) for param in |
1482 | 1516 |
connectionPoint), |
1483 | 1517 |
baseSymbol, additionalSymbol, isExceptDetect, detectFlip=1 if detectFlip else 0, |
1484 |
hasInstrumentLabel=hasInstrumentLabel) |
|
1518 |
hasInstrumentLabel=hasInstrumentLabel, text_area=text_area)
|
|
1485 | 1519 |
|
1486 | 1520 |
searchedSymbolList.append(newSym) |
1487 | 1521 |
except Exception as ex: |
DTI_PID/DTI_PID/TextInfo.py | ||
---|---|---|
8 | 8 |
self.angle = angle |
9 | 9 |
|
10 | 10 |
@property |
11 |
def area(self): |
|
12 |
""" |
|
13 |
return area of area |
|
14 |
""" |
|
15 |
return self.w*self.h |
|
16 |
|
|
17 |
def contains(self, pt): |
|
18 |
if len(pt) == 2: |
|
19 |
if pt[0] < self.x: return False |
|
20 |
if pt[0] > self.x + self.w: return False |
|
21 |
if pt[1] < self.y: return False |
|
22 |
if pt[1] > self.y + self.h: return False |
|
23 |
elif len(pt) == 4: |
|
24 |
minx = pt[0] |
|
25 |
miny = pt[1] |
|
26 |
maxx = pt[2] |
|
27 |
maxy = pt[3] |
|
28 |
|
|
29 |
if minx < self.x: return False |
|
30 |
if maxx > self.x + self.w: return False |
|
31 |
if miny < self.y: return False |
|
32 |
if maxy > self.y + self.h: return False |
|
33 |
|
|
34 |
return True |
|
35 |
|
|
36 |
@property |
|
11 | 37 |
def center(self): |
12 | 38 |
""" |
13 | 39 |
return center of text |
내보내기 Unified diff