(mesh, info_on_pix, image, depth)
| 545 | |
| 546 | |
| 547 | def refresh_bord_depth(mesh, info_on_pix, image, depth): |
| 548 | H, W = mesh.graph['H'], mesh.graph['W'] |
| 549 | corner_nodes = [(mesh.graph['bord_up'], mesh.graph['bord_left']), |
| 550 | (mesh.graph['bord_up'], mesh.graph['bord_right'] - 1), |
| 551 | (mesh.graph['bord_down'] - 1, mesh.graph['bord_left']), |
| 552 | (mesh.graph['bord_down'] - 1, mesh.graph['bord_right'] - 1)] |
| 553 | # (0, W - 1), (H - 1, 0), (H - 1, W - 1)] |
| 554 | bord_nodes = [] |
| 555 | bord_nodes += [(mesh.graph['bord_up'], xx) for xx in range(mesh.graph['bord_left'] + 1, mesh.graph['bord_right'] - 1)] |
| 556 | bord_nodes += [(mesh.graph['bord_down'] - 1, xx) for xx in range(mesh.graph['bord_left'] + 1, mesh.graph['bord_right'] - 1)] |
| 557 | bord_nodes += [(xx, mesh.graph['bord_left']) for xx in range(mesh.graph['bord_up'] + 1, mesh.graph['bord_down'] - 1)] |
| 558 | bord_nodes += [(xx, mesh.graph['bord_right'] - 1) for xx in range(mesh.graph['bord_up'] + 1, mesh.graph['bord_down'] - 1)] |
| 559 | for xy in bord_nodes: |
| 560 | tgt_loc = None |
| 561 | if xy[0] == mesh.graph['bord_up']: |
| 562 | tgt_loc = (xy[0] + 1, xy[1])# (1, xy[1]) |
| 563 | elif xy[0] == mesh.graph['bord_down'] - 1: |
| 564 | tgt_loc = (xy[0] - 1, xy[1]) # (H - 2, xy[1]) |
| 565 | elif xy[1] == mesh.graph['bord_left']: |
| 566 | tgt_loc = (xy[0], xy[1] + 1) |
| 567 | elif xy[1] == mesh.graph['bord_right'] - 1: |
| 568 | tgt_loc = (xy[0], xy[1] - 1) |
| 569 | if tgt_loc is not None: |
| 570 | ne_infos = info_on_pix.get(tgt_loc) |
| 571 | if ne_infos is None: |
| 572 | import pdb; pdb.set_trace() |
| 573 | # if ne_infos is not None and len(ne_infos) == 1: |
| 574 | tgt_depth = ne_infos[0]['depth'] |
| 575 | tgt_disp = ne_infos[0]['disp'] |
| 576 | new_node = (xy[0], xy[1], tgt_depth) |
| 577 | src_node = (tgt_loc[0], tgt_loc[1], tgt_depth) |
| 578 | tgt_nes_loc = [(xx[0], xx[1]) \ |
| 579 | for xx in mesh.neighbors(src_node)] |
| 580 | tgt_nes_loc = [(xx[0] - tgt_loc[0] + xy[0], xx[1] - tgt_loc[1] + xy[1]) for xx in tgt_nes_loc \ |
| 581 | if abs(xx[0] - xy[0]) == 1 and abs(xx[1] - xy[1]) == 1] |
| 582 | tgt_nes_loc = [xx for xx in tgt_nes_loc if info_on_pix.get(xx) is not None] |
| 583 | tgt_nes_loc.append(tgt_loc) |
| 584 | # if (xy[0], xy[1]) == (559, 60): |
| 585 | # import pdb; pdb.set_trace() |
| 586 | if info_on_pix.get(xy) is not None and len(info_on_pix.get(xy)) > 0: |
| 587 | old_depth = info_on_pix[xy][0].get('depth') |
| 588 | old_node = (xy[0], xy[1], old_depth) |
| 589 | mesh.remove_edges_from([(old_ne, old_node) for old_ne in mesh.neighbors(old_node)]) |
| 590 | mesh.add_edges_from([((zz[0], zz[1], info_on_pix[zz][0]['depth']), old_node) for zz in tgt_nes_loc]) |
| 591 | mapping_dict = {old_node: new_node} |
| 592 | # if old_node[2] == new_node[2]: |
| 593 | # print("mapping_dict = ", mapping_dict) |
| 594 | info_on_pix, mesh = update_info(mapping_dict, info_on_pix, mesh) |
| 595 | else: |
| 596 | info_on_pix[xy] = [] |
| 597 | info_on_pix[xy][0] = info_on_pix[tgt_loc][0] |
| 598 | info_on_pix['color'] = image[xy[0], xy[1]] |
| 599 | info_on_pix['old_color'] = image[xy[0], xy[1]] |
| 600 | mesh.add_node(new_node) |
| 601 | mesh.add_edges_from([((zz[0], zz[1], info_on_pix[zz][0]['depth']), new_node) for zz in tgt_nes_loc]) |
| 602 | mesh.nodes[new_node]['far'] = None |
| 603 | mesh.nodes[new_node]['near'] = None |
| 604 | if mesh.nodes[src_node].get('far') is not None: |
no test coverage detected