개정판 9e7d6541
issue #663: line type detection test
Change-Id: I5a60c809652270977d1c333fe34f95b981f3f586
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
3825 | 3825 |
sys.exc_info()[-1].tb_lineno) |
3826 | 3826 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
3827 | 3827 |
|
3828 |
self.activeDrawing.view_rect = rect |
|
3829 |
self.update_view_region(self.activeDrawing) |
|
3828 |
if rect: |
|
3829 |
self.activeDrawing.view_rect = rect |
|
3830 |
self.update_view_region(self.activeDrawing) |
|
3830 | 3831 |
|
3831 | 3832 |
def update_view_region(self, drawing): |
3832 | 3833 |
"""update view region""" |
... | ... | |
3836 | 3837 |
cursor = conn.cursor() |
3837 | 3838 |
|
3838 | 3839 |
# check if there is view region |
3839 |
sql = f"select count(*) from Views where Drawings_UID=?"
|
|
3840 |
params = [drawing.UID]
|
|
3840 |
sql = f"select Drawings_UID from Views where Drawings_UID=?"
|
|
3841 |
params = (drawing.UID,)
|
|
3841 | 3842 |
cursor.execute(self.project.database.to_sql(sql), params) |
3842 | 3843 |
rows = cursor.fetchall() |
3843 |
if rows[0][0]:
|
|
3844 |
if rows: |
|
3844 | 3845 |
sql = f"update Views set X=?,Y=?,Width=?,Height=? where Drawings_UID=?" |
3845 | 3846 |
params = (drawing.view_rect.x(), drawing.view_rect.y(), |
3846 | 3847 |
drawing.view_rect.width(), drawing.view_rect.height(), drawing.UID) |
... | ... | |
3851 | 3852 |
|
3852 | 3853 |
sql = self.project.database.to_sql(sql) |
3853 | 3854 |
cursor.execute(sql, params) |
3855 |
conn.commit() |
|
3854 | 3856 |
# Catch the exception |
3855 | 3857 |
except Exception as ex: |
3856 | 3858 |
|
DTI_PID/DTI_PID/Commands/SaveWorkCommand.py | ||
---|---|---|
38 | 38 |
|
39 | 39 |
all_items = self.target_scene.items() |
40 | 40 |
"""get view region""" |
41 |
viewer = self.target_scene.views()[0] |
|
42 |
rect = viewer.viewport().rect() |
|
43 |
view_rect = viewer.mapToScene(rect).boundingRect() |
|
41 |
views = self.target_scene.views() |
|
42 |
view_rect = None |
|
43 |
if views: |
|
44 |
viewer = views[0] |
|
45 |
rect = viewer.viewport().rect() |
|
46 |
view_rect = viewer.mapToScene(rect).boundingRect() |
|
44 | 47 |
"""up to here""" |
45 | 48 |
|
46 | 49 |
items = [] |
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
1274 | 1274 |
if sym.conn_type: |
1275 | 1275 |
for index in range(len(sym.conn_type)): |
1276 | 1276 |
item = sym.connectors[index].connectedItem |
1277 |
if item and type(item) is QEngineeringLineItem: |
|
1277 |
if item and type(item) is QEngineeringLineItem and sym.conn_type[index] != 'Secondary' and sym.conn_type[index] != 'Primary':
|
|
1278 | 1278 |
Worker.changeConnectedLineType(item, sym.conn_type[index]) |
1279 | 1279 |
|
1280 | 1280 |
except Exception as ex: |
... | ... | |
1345 | 1345 |
f"{sys.exc_info()[-1].tb_lineno}" |
1346 | 1346 |
worker.displayLog.emit(MessageType.Error, message) |
1347 | 1347 |
# up to here |
1348 |
|
|
1348 |
print('flag4') |
|
1349 | 1349 |
worker.create_unknown_items(mainRes) |
1350 | 1350 |
worker.add_detected_items_to_scene.emit(worker.scene, flange_list) |
1351 | 1351 |
worker.cond.wait(worker.mutex) |
... | ... | |
1408 | 1408 |
worker.displayLog.emit(MessageType.Error, message) |
1409 | 1409 |
# up to here |
1410 | 1410 |
|
1411 |
print('flag5') |
|
1411 | 1412 |
worker.save_scene.emit(worker.scene) |
1412 | 1413 |
worker.cond.wait(worker.mutex) |
1413 | 1414 |
|
... | ... | |
1457 | 1458 |
|
1458 | 1459 |
contours, _ = cv2.findContours(line_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
1459 | 1460 |
|
1461 |
line_thickness = 0 |
|
1462 |
|
|
1460 | 1463 |
if len(contours) < 3: |
1461 | 1464 |
max_x, max_y, min_x, min_y = 0, 0, sys.maxsize, sys.maxsize |
1462 | 1465 |
for rect in [cv2.boundingRect(contour) for contour in contours]: |
... | ... | |
1469 | 1472 |
if rect[1] + rect[3] > max_y: |
1470 | 1473 |
max_y = rect[1] + rect[3] |
1471 | 1474 |
|
1475 |
thickness = min(max_y - min_y, max_x - max_x) |
|
1476 |
if line_thickness < thickness: |
|
1477 |
line_thickness = thickness |
|
1478 |
|
|
1472 | 1479 |
line_shapes.append([line_img[min_y:max_y, min_x:max_x], sys.maxsize, line.getThreshold(), line.getBaseSymbol()]) |
1473 | 1480 |
continue |
1474 | 1481 |
|
... | ... | |
1496 | 1503 |
|
1497 | 1504 |
# skip piping line |
1498 | 1505 |
if len(contours) < 3 or (sum([cv2.contourArea(contour) for contour in contours]) / len(contours)) > max_avg_area * 2: |
1506 |
if rect.width() > rect.height(): |
|
1507 |
image_line = image[round(rect.y() - line_thickness / 2):round(rect.y() + rect.height() + line_thickness / 2), round(rect.x() - 1):round(rect.x() + rect.width() + 1)] |
|
1508 |
else: |
|
1509 |
image_line = image[round(rect.y() - 1):round(rect.y() + rect.height() + 1), round(rect.x() - line_thickness / 2):round(rect.x() + rect.width() + line_thickness / 2)] |
|
1510 |
|
|
1511 |
contours, _ = cv2.findContours(image_line, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
|
1499 | 1512 |
max_x, max_y, min_x, min_y = 0, 0, sys.maxsize, sys.maxsize |
1500 | 1513 |
for rect in [cv2.boundingRect(contour) for contour in contours]: |
1501 | 1514 |
if rect[0] < min_x: |
... | ... | |
1540 | 1553 |
|
1541 | 1554 |
line_pattern[2] = min_error |
1542 | 1555 |
|
1543 |
line_type_founds = sorted([(line_pattern[-1], 1 - line_pattern[-2] - line_pattern[2]) for line_pattern in line_patterns \ |
|
1544 |
if line_pattern[2] < (1 - line_pattern[-2])], key=lambda error:error[1], reverse=True) |
|
1556 |
line_type_founds = sorted([(line_pattern[-1], line_pattern[2]) for line_pattern in line_patterns], key=lambda error:error[1]) |
|
1545 | 1557 |
if line_type_founds: |
1546 | 1558 |
lines_found.append([line, line_type_founds[0]]) |
1547 | 1559 |
|
... | ... | |
1621 | 1633 |
if searchedInfos: |
1622 | 1634 |
line_shape[1] = sorted(searchedInfos)[0] |
1623 | 1635 |
|
1624 |
line_type_founds = sorted([(line_shape[-1], 1 - line_shape[-2] - line_shape[1]) for line_shape in line_shapes], key=lambda error: error[1], reverse=True) |
|
1636 |
line_type_founds = sorted([(line_shape[-1], (1 - line_shape[-2] - line_shape[1]) * 2) for line_shape in line_shapes \ |
|
1637 |
if line_shape[1] < (1 - line_shape[-2])], key=lambda error: error[1], reverse=True) |
|
1625 | 1638 |
if line_type_founds: |
1626 | 1639 |
lines_found.append([line, line_type_founds[0]]) |
1627 | 1640 |
''' |
내보내기 Unified diff