Exemplo n.º 1
0
def _redraw(window1, window2, gif_window):
    window1.update_cached_zoomed_img()
    window2.update_cached_zoomed_img()
    window1.redraw()
    window2.redraw()
    # If at least 4 points are present, we can compute H from window1 to window2.
    if len(window1.points) >= 4:
        # Points have (x, y) order.
        src_pts = np.asarray([p[0] for p in window1.points])
        dst_pts = np.asarray([p[0] for p in window2.points])
        H, matches_mask = cv2.findHomography(src_pts,
                                             dst_pts,
                                             method=cv2.RANSAC)
        #matches_mask = matches_mask.ravel().tolist()
        warped = warp(window1.img, H, None, window2.img.shape[0:2])
        dst = window2.img.copy()
        warped_pts = np.asarray(
            [transformPoint(H, pt[0], pt[1]) for pt in src_pts])
        for (x1, y1), (x2, y2) in zip(warped_pts.astype(int),
                                      dst_pts.astype(int)):
            cv2.arrowedLine(warped, (x1, y1), (x2, y2),
                            color=(255, 0, 0),
                            thickness=2)
            cv2.arrowedLine(dst, (x1, y1), (x2, y2),
                            color=(255, 0, 0),
                            thickness=2)
        gif_window.update_images(dst, warped)
Exemplo n.º 2
0
def wrapVisibilityFrameToMap(H, src_shape, dst_shape, height):
  ''' Wrap the visible part of the frame into map. '''

  frameH, frameW = src_shape[0], src_shape[1]
  mapH, mapW = dst_shape[0], dst_shape[1]
  visibleframe = np.ones((frameH, frameW), np.uint8) * 255

  # Horizon line.
  horizon = H[2,:].copy().transpose()
  logging.debug('Horizon line: %s' % str(horizon))
  assert horizon[1] != 0
  x1 = 0
  x2 = frameW-1
  y1 = int(- (horizon[0] * x1 + horizon[2]) / horizon[1])
  y2 = int(- (horizon[0] * x2 + horizon[2]) / horizon[1])

  # Visible part in the frame.
  cv2.fillPoly(visibleframe, np.asarray([[(x1,y1),(x2,y2),(x2,0),(x1,0)]]), (0,))

  # Visible part in the bigpic.
  visiblemap = warp(visibleframe, H, (frameH, frameW), (mapH, mapW))
  return visiblemap
Exemplo n.º 3
0
  logging.info ('Discriminant for origin computation: %.2f' % d)
  # Assume the camera is not looking that much down.
  X0 = (1. + d) / 2 * X1 + (1. - d) / 2 * X2
  logging.info('Camera origin (x,y) on the map: (%d,%d)' % (X0[0], X0[1]))
  cv2.circle(satellite, (int(X0[0]),int(X0[1])), 6, (0,255,0), 4)

  # Save. Propagate this infomation forward on to map.json.
  if args.update_map_json:
    pose.map['map_origin'] = {
        'x': int(X0[0]), 'y': int(X0[1]), 
        'comment': 'computed by ComputeH from pose%d' % pose.pose_id
    }
  pose.save(backup=not args.no_backup)

  # Warp satellite for nice visualization.
  warped_satellite = warp(satellite, np.linalg.inv(H), (mapH, mapW), (frameH, frameW))
  warped_path = op.join(pose.get_pose_dir(), 'satellite-warped-map%d.gif' % pose.map_id)
  poseframe = pose.load_example()
  with get_writer(warped_path, mode='I') as writer:
    N = 15
    for i in range(N):
      writer.append_data(getGifFrame(warped_satellite, poseframe, float(i) / N))

  # Make visibility map.
  # Horizon line.
  horizon = H[2,:].copy().transpose()
  logging.debug('Horizon line: %s' % str(horizon))
  assert horizon[1] != 0
  x1 = 0
  x2 = frameW-1
  y1 = int(- (horizon[0] * x1 + horizon[2]) / horizon[1])