Input: image: HxWx3 numpy flow: HxWx2 torch.Tensor Output: outImg: HxWx3 numpy
(image, flow, padding_mode='zeros')
| 47 | return coords[None].repeat(batch, 1, 1, 1) |
| 48 | |
| 49 | def image_flow_warp(image, flow, padding_mode='zeros'): |
| 50 | ''' |
| 51 | Input: |
| 52 | image: HxWx3 numpy |
| 53 | flow: HxWx2 torch.Tensor |
| 54 | Output: |
| 55 | outImg: HxWx3 numpy |
| 56 | ''' |
| 57 | image = torch.from_numpy(image) |
| 58 | if image.ndim == 2: |
| 59 | image = image[None].permute([1,2,0]) |
| 60 | H, W, _ = image.shape |
| 61 | coords = coords_grid(1, H, W).cuda().float().contiguous() |
| 62 | flow = flow[None].repeat(1, 1, 1, 1).permute([0, 3, 1, 2]).float().contiguous() |
| 63 | grid = (flow + coords).permute([0, 2, 3, 1]).contiguous() # (1, H, W, 2) |
| 64 | |
| 65 | grid[:, :, :, 0] = (grid[:, :, :, 0] * 2 - W + 1) / (W - 1) |
| 66 | grid[:, :, :, 1] = (grid[:, :, :, 1] * 2 - H + 1) / (H - 1) |
| 67 | image = image[None].permute([0, 3, 1, 2]).cuda().float() |
| 68 | |
| 69 | outImg = F.grid_sample(image, grid, padding_mode=padding_mode, align_corners=False)[0].cpu().numpy().transpose([1, 2, 0]) |
| 70 | return outImg |
| 71 | |
| 72 | def blend(estimator, marker, scene, frame, args, warp = 'homography'): |
| 73 | H, W = 480, 640 |