61 |
61 |
finished = pyqtSignal()
|
62 |
62 |
intReady = pyqtSignal(int)
|
63 |
63 |
displayTitle = pyqtSignal(str)
|
64 |
|
#drawDetectedItems = pyqtSignal(list, list, list, list, QObject)
|
65 |
|
#drawDetectedLines = pyqtSignal(list, QObject)
|
66 |
|
#drawUnknownItems = pyqtSignal(str, QObject)
|
67 |
64 |
displayMessage = pyqtSignal(QListWidgetItem)
|
68 |
65 |
updateProgress = pyqtSignal(int, str)
|
69 |
66 |
updateBatchProgress = pyqtSignal(int, int)
|
... | ... | |
632 |
629 |
overlapArea = 0
|
633 |
630 |
symbolIndex = -1
|
634 |
631 |
for i in range(len(searchedSymbolList)):
|
635 |
|
'''
|
636 |
|
_pt = searchedSymbolList[i].getSp()
|
637 |
|
rect = QRectF(_pt[0], _pt[1], searchedSymbolList[i].getWidth(), searchedSymbolList[i].getHeight())
|
638 |
|
_rect = QRectF(searchedItemSp[0], searchedItemSp[1], sw, sh)
|
639 |
|
if rect.intersects(_rect):
|
640 |
|
intersect = rect.intersected(_rect)
|
641 |
|
overlapArea = intersect.width()*intersect.height()
|
642 |
|
if overlapArea > sw*sh*0.1:
|
|
632 |
area = Worker.contains(searchedSymbolList[i], searchedItemSp, sw, sh)
|
|
633 |
if area > ACCEPT_OVERLAY_AREA:
|
|
634 |
if area > overlapArea:
|
|
635 |
overlapArea = area
|
643 |
636 |
symbolIndex = i
|
644 |
|
break
|
645 |
|
'''
|
646 |
|
overlapArea = Worker.contains(searchedSymbolList[i], searchedItemSp, sw, sh)
|
647 |
|
if overlapArea > ACCEPT_OVERLAY_AREA:
|
|
637 |
"""
|
648 |
638 |
categories = [appDocData.isEquipmentType(symbolType), appDocData.isEquipmentType(searchedSymbolList[i].getType())]
|
649 |
639 |
if categories[0] == categories[1]:
|
650 |
640 |
symbolIndex = i
|
651 |
641 |
break
|
|
642 |
"""
|
652 |
643 |
|
653 |
644 |
hitRate = tmRes[pt[1], pt[0]]
|
654 |
645 |
|
... | ... | |
675 |
666 |
','.join(str(x) for x in originalPoint),
|
676 |
667 |
'/'.join('{},{},{}'.format(param[0], param[1], param[2]) for param in connectionPoint),
|
677 |
668 |
baseSymbol, additionalSymbol,isExceptDetect)
|
678 |
|
## DEBUG
|
679 |
|
##message = '//// {}:{}-{} ////'.format(symbolName, searchedItemSp, hitRate)
|
680 |
|
##worker.displayLog.emit(MessageType.Normal, message)
|
681 |
|
## up to here
|
682 |
|
|
683 |
669 |
threadLock.release()
|
684 |
670 |
## 현재 심볼과 검출된 심볼이 같지 않을 경우 (포함)
|
685 |
671 |
elif appDocData.isEquipmentType(searchedSymbol.getType()):
|
686 |
|
## DEBUG
|
687 |
|
message = '{}->{}:{}-{}'.format(searchedSymbol.getName(), symbolName, searchedItemSp, hitRate)
|
688 |
|
worker.displayLog.emit(MessageType.Normal, message)
|
689 |
|
## up to here
|
690 |
|
|
691 |
|
threadLock.acquire()
|
692 |
|
foundSymbolCount = foundSymbolCount + 1
|
693 |
|
Worker.addSearchedSymbol(symbolName, symbolType ,
|
694 |
|
searchedItemSp, sw, sh, symbolThreshold, hitRate, hitRate, symbolRotatedAngle ,
|
695 |
|
isDetectOnOrigin, symbolRotateCount, symbolOcrOption, isContainChild ,
|
696 |
|
originalPoint, connectionPoint, baseSymbol, additionalSymbol,isExceptDetect)
|
697 |
|
threadLock.release()
|
698 |
|
|
|
672 |
if searchedSymbol.area > sw*sh*10: # searched equipment area is greather than 10 times of symbol's area
|
|
673 |
threadLock.acquire()
|
|
674 |
foundSymbolCount = foundSymbolCount + 1
|
|
675 |
Worker.addSearchedSymbol(symbolName, symbolType ,
|
|
676 |
searchedItemSp, sw, sh, symbolThreshold, hitRate, hitRate, symbolRotatedAngle ,
|
|
677 |
isDetectOnOrigin, symbolRotateCount, symbolOcrOption, isContainChild ,
|
|
678 |
originalPoint, connectionPoint, baseSymbol, additionalSymbol,isExceptDetect)
|
|
679 |
threadLock.release()
|
|
680 |
else:
|
|
681 |
searchedSymbol = searchedSymbolList[symbolIndex]
|
|
682 |
symbolHitRate = searchedSymbol.getHitRate()
|
|
683 |
if symbolHitRate < hitRate:
|
|
684 |
threadLock.acquire()
|
|
685 |
searchedSymbolList[symbolIndex] = symbol.Symbol(symbolName, symbolType ,
|
|
686 |
searchedItemSp, sw, sh, symbolThreshold, symbolMinMatchCount, hitRate, symbolRotatedAngle ,
|
|
687 |
isDetectOnOrigin, symbolRotateCount, symbolOcrOption, isContainChild ,
|
|
688 |
','.join(str(x) for x in originalPoint),
|
|
689 |
'/'.join('{},{},{}'.format(param[0], param[1], param[2]) for param in connectionPoint),
|
|
690 |
baseSymbol, additionalSymbol,isExceptDetect)
|
|
691 |
threadLock.release()
|
|
692 |
|
699 |
693 |
## Rotate Symbol
|
700 |
694 |
symGray = cv2.rotate(symGray, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
701 |
695 |
symbolRotatedAngle = symbolRotatedAngle + 90
|
... | ... | |
1448 |
1442 |
|
1449 |
1443 |
try:
|
1450 |
1444 |
self.ui.buttonBox.setEnabled(True)
|
1451 |
|
|
|
1445 |
|
|
1446 |
self.ui.progressBar.setValue(self.ui.progressBar.maximum())
|
1452 |
1447 |
#if not self.batch:
|
1453 |
1448 |
# self.parent.drawDetectedItemsToScene()
|
1454 |
1449 |
except Exception as ex:
|
... | ... | |
1497 |
1492 |
try:
|
1498 |
1493 |
self.parent.drawUnknownItems(path)
|
1499 |
1494 |
finally:
|
1500 |
|
loop.quit()
|
1501 |
|
|
1502 |
|
'''
|
1503 |
|
@history 2018.05.25 Jeongwoo Moved from MainWindow
|
1504 |
|
2018.05.28 Jeongwoo Add xmlPath Parameter and append LineInfo into xml
|
1505 |
|
2018.05.29 Jeongwoo Change method to add item
|
1506 |
|
2018.05.30 Jeongwoo Remove parameter (xmlPath)
|
1507 |
|
humkyung 2018.06.11 add drawing path to parameter and write recognized lines to image
|
1508 |
|
humkyung 2018.07.04 call arrangeLinePosition after creating line
|
1509 |
|
'''
|
1510 |
|
'''
|
1511 |
|
def recognizeLine(self, path, listWidget, graphicsView, worker):
|
1512 |
|
from shapely.geometry import Point, LineString
|
1513 |
|
from SymbolSvgItem import SymbolSvgItem
|
1514 |
|
from QEngineeringFlowArrowItem import QEngineeringFlowArrowItem
|
1515 |
|
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
|
1516 |
|
from EngineeringTextItem import QEngineeringTextItem
|
1517 |
|
from EngineeringLineItem import QEngineeringLineItem
|
1518 |
|
from LineDetector import LineDetector
|
1519 |
|
|
1520 |
|
try:
|
1521 |
|
listWidget.addItem('Starting line recognization')
|
1522 |
|
|
1523 |
|
#remove already existing line and flow arrow item
|
1524 |
|
items = [item for item in worker.graphicsView.scene.items() if (type(item) is QEngineeringLineItem) or (type(item) is QEngineeringFlowArrowItem)]
|
1525 |
|
for item in items:
|
1526 |
|
worker.graphicsView.scene.removeItem(item)
|
1527 |
|
#up to here
|
1528 |
|
|
1529 |
|
# detect line
|
1530 |
|
connectedLines = []
|
1531 |
|
|
1532 |
|
area = AppDocData.instance().getArea('Drawing')
|
1533 |
|
area.img = worker.removeSmallObjects(area.img)
|
1534 |
|
detector = LineDetector(area.img)
|
1535 |
|
|
1536 |
|
symbols = []
|
1537 |
|
for item in worker.graphicsView.scene.items():
|
1538 |
|
if issubclass(type(item), SymbolSvgItem):
|
1539 |
|
symbols.append(item)
|
1540 |
|
res = detector.detectConnectedLine(item, round(area.x), round(area.y))
|
1541 |
|
if res is not None:
|
1542 |
|
connectedLines.extend(res)
|
1543 |
|
|
1544 |
|
listWidget.addItem('Connecting lines')
|
1545 |
|
if len(connectedLines) > 1:
|
1546 |
|
detector.mergeLines(connectedLines, toler=5)
|
1547 |
|
# connect line to symbol
|
1548 |
|
try:
|
1549 |
|
for line in connectedLines:
|
1550 |
|
matches = [symbol for symbol in symbols if symbol.isConnectable(line, (round(area.x), round(area.y)), toler=20)]
|
1551 |
|
for symbol in matches:
|
1552 |
|
detector.connectLineToSymbol(line, (round(area.x), round(area.y)), symbol)
|
1553 |
|
except Exception as ex:
|
1554 |
|
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
1555 |
|
MainWindow.instance().displayMessage.emit(MessageType.Error, message)
|
1556 |
|
# up to here
|
1557 |
|
|
1558 |
|
# connect line to line
|
1559 |
|
toler = 10
|
1560 |
|
try:
|
1561 |
|
for line in connectedLines:
|
1562 |
|
matches = [it for it in connectedLines if (it is not line) and (not detector.isParallel(line, it))]
|
1563 |
|
|
1564 |
|
# get closest line
|
1565 |
|
selected = []
|
1566 |
|
shapelyLine = LineString(line)
|
1567 |
|
for match in matches:
|
1568 |
|
dist = [shapelyLine.distance(Point(match[0][0], match[0][1])),shapelyLine.distance(Point(match[1][0], match[1][1]))]
|
1569 |
|
if dist[0] < toler or dist[1] < toler:
|
1570 |
|
selected.append(match)
|
1571 |
|
# up to here
|
1572 |
|
|
1573 |
|
for match in selected:
|
1574 |
|
detector.connectLineToLine(match, line, toler)
|
1575 |
|
except Exception as ex:
|
1576 |
|
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
1577 |
|
workder.displayLog.emit(MessageType.Error, message)
|
1578 |
|
# up to here
|
1579 |
|
|
1580 |
|
for pts in connectedLines:
|
1581 |
|
processLine = QEngineeringLineItem(vertices=[(area.x + param[0], area.y + param[1]) for param in pts])
|
1582 |
|
graphicsView.scene.addItem(processLine)
|
1583 |
|
#lines.append(processLine)
|
1584 |
|
|
1585 |
|
if processLine.length() > 100: # TODO: check critical length
|
1586 |
|
processLine.addFlowArrow()
|
1587 |
|
|
1588 |
|
# re-order process line's start,end according to flow mark
|
1589 |
|
worker.arrangeLinePosition(lines, symbols, listWidget)
|
1590 |
|
# up to here
|
1591 |
|
except Exception as ex:
|
1592 |
|
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
1593 |
|
worker.displayLog.emit(MessageType.Error, message)
|
1594 |
|
finally:
|
1595 |
|
listWidget.addItem('Finished line recognization')
|
1596 |
|
worker.finished.emit()
|
1597 |
|
'''
|
|
1495 |
loop.quit()
|