개정판 6777ecae
issue #1366: if merge and change big tile size
Change-Id: I697f1147c0f8bcfe995741b34b6e729d81d5edd9
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
2388 | 2388 |
sow, soh = symGray.shape[::-1] |
2389 | 2389 |
|
2390 | 2390 |
# symbol is bigger than roi -> detected symbol area is too big |
2391 |
if rect[3] * rect[4] > sow * soh * 1.5:
|
|
2391 |
if rect[3] * rect[4] > sow * soh * 1.6:
|
|
2392 | 2392 |
return (None, None, None, None, None, None, None) |
2393 | 2393 |
# detected symbol area is too small |
2394 |
elif rect[3] * rect[4] * 1.5 < sow * soh:
|
|
2394 |
elif rect[3] * rect[4] * 1.6 < sow * soh:
|
|
2395 | 2395 |
return (None, None, None, None, None, None, None) |
2396 | 2396 |
|
2397 | 2397 |
# get Rotated Original Point |
2398 | 2398 |
sow, soh = symGray.shape[::-1] |
2399 |
offset = int(max(sow, soh) / 2)
|
|
2399 |
offset_x, offset_y = round(rect[3] * 0.3), round(rect[4] * 0.3)#int(max(sow, soh) / 2)
|
|
2400 | 2400 |
|
2401 | 2401 |
roiItem = Worker.remove_small_objects(area.img, 0, sow * soh * 0.5) if hasInstrumentLabel else area.img.copy() |
2402 |
x_start = round(rect[1]) - round(offset) if round(rect[1]) - round(offset) > 0 else 0
|
|
2403 |
y_start = round(rect[2]) - round(offset) if round(rect[2]) - round(offset) > 0 else 0
|
|
2404 |
x_max = round(rect[1]) + round(rect[3]) + round(offset) if round(rect[1]) + round(rect[3]) + round(offset) < len(roiItem[0]) else len(roiItem[0]) - 1
|
|
2405 |
y_max = round(rect[2]) + round(rect[4]) + round(offset) if round(rect[2]) + round(rect[4]) + round(offset) < len(roiItem) else len(roiItem) - 1
|
|
2402 |
x_start = round(rect[1]) - round(offset_x) if round(rect[1]) - round(offset_x) > 0 else 0
|
|
2403 |
y_start = round(rect[2]) - round(offset_y) if round(rect[2]) - round(offset_y) > 0 else 0
|
|
2404 |
x_max = round(rect[1]) + round(rect[3]) + round(offset_x) if round(rect[1]) + round(rect[3]) + round(offset_x) < len(roiItem[0]) else len(roiItem[0]) - 1
|
|
2405 |
y_max = round(rect[2]) + round(rect[4]) + round(offset_y) if round(rect[2]) + round(rect[4]) + round(offset_y) < len(roiItem) else len(roiItem) - 1
|
|
2406 | 2406 |
roiItem = roiItem[y_start:y_max, x_start:x_max] |
2407 | 2407 |
|
2408 | 2408 |
symGrayOri = copy.copy(symGray) |
... | ... | |
2468 | 2468 |
app_web_service = AppWebService() |
2469 | 2469 |
symbols = app_web_service.request_symbol_box(project.name, area.img) |
2470 | 2470 |
|
2471 |
# merge symbol box |
|
2472 |
overlap_merges = [] |
|
2473 |
for rect1 in symbols: |
|
2474 |
for rect2 in symbols: |
|
2475 |
if rect1 is rect2 or rect1[0] != rect2[0]: |
|
2476 |
continue |
|
2477 |
l1, l2 = rect1[1], rect2[1] |
|
2478 |
r1, r2 = rect1[1] + rect1[3], rect2[1] + rect2[3] |
|
2479 |
l_x, s_x = [l1, r1], [l2, r2] |
|
2480 |
t1, t2 = rect1[2], rect2[2] |
|
2481 |
b1, b2 = rect1[2] + rect1[4], rect2[2] + rect2[4] |
|
2482 |
l_y, s_y = [t1, b1], [t2, b2] |
|
2483 |
if not (max(l_x) < min(s_x) or max(s_x) < min(l_x)) and \ |
|
2484 |
not (max(l_y) < min(s_y) or max(s_y) < min(l_y)): |
|
2485 |
inserted = False |
|
2486 |
for merge in overlap_merges: |
|
2487 |
if (rect1 in merge) and (rect2 in merge): |
|
2488 |
inserted = True |
|
2489 |
break |
|
2490 |
elif (rect1 in merge) and (rect2 not in merge): |
|
2491 |
merge.append(rect2) |
|
2492 |
inserted = True |
|
2493 |
break |
|
2494 |
elif (rect2 in merge) and (rect1 not in merge): |
|
2495 |
merge.append(rect1) |
|
2496 |
inserted = True |
|
2497 |
break |
|
2498 |
if not inserted: |
|
2499 |
overlap_merges.append([rect1, rect2]) |
|
2500 |
|
|
2501 |
for merge in overlap_merges: |
|
2502 |
for rect in merge: |
|
2503 |
if rect in symbols: |
|
2504 |
symbols.remove(rect) |
|
2505 |
else: |
|
2506 |
pass |
|
2507 |
#print(str(rect)) |
|
2508 |
|
|
2509 |
for merge in overlap_merges: |
|
2510 |
max_x, max_y, min_x, min_y = 0, 0, sys.maxsize, sys.maxsize |
|
2511 |
ratio = 0 |
|
2512 |
for rect in merge: |
|
2513 |
if rect[5] > ratio: |
|
2514 |
ratio = rect[5] |
|
2515 |
|
|
2516 |
if rect[1] < min_x: |
|
2517 |
min_x = rect[1] |
|
2518 |
if rect[1] + rect[3] > max_x: |
|
2519 |
max_x = rect[1] + rect[3] |
|
2520 |
if rect[2] < min_y: |
|
2521 |
min_y = rect[2] |
|
2522 |
if rect[2] + rect[4] > max_y: |
|
2523 |
max_y = rect[2] + rect[4] |
|
2524 |
|
|
2525 |
rect = [rect[0], min_x, min_y, max_x - min_x, max_y - min_y, ratio] |
|
2526 |
symbols.append(rect) |
|
2527 |
# up to here |
|
2528 |
|
|
2471 | 2529 |
for targetSymbol in targetSymbols[2]: |
2472 | 2530 |
symbolName = targetSymbol.getName() |
2473 | 2531 |
symbolType = targetSymbol.getType() |
DTI_PID/WebServer/symbol_recognition/test_doftech_all_images.py | ||
---|---|---|
104 | 104 |
l_image = img_list[idx_img].copy() |
105 | 105 |
|
106 | 106 |
small_object_patch_list.append(get_patch(s_image, 500, 250)) |
107 |
large_object_patch_list.append(get_patch(l_image, 850, 200))
|
|
107 |
large_object_patch_list.append(get_patch(l_image, 1000, 400))
|
|
108 | 108 |
|
109 | 109 |
img_name = str(idx_img) |
110 | 110 |
|
내보내기 Unified diff