Beispiel #1
0
def _gapsview(d,
              msh=None,
              pts=None,
              grd=None,
              world2grid=None,
              grid_threshold=0.0,
              camera='default'):
    """Interactively views a mesh, pointcloud, and/or grid at the same time."""
    assert msh is not None or pts is not None or grd is not None
    mpath = ''
    ppath = ''
    gpath = ''
    init_camera = _setup_cam(camera)
    if msh is not None:
        mpath = d + '/m.ply'
        file_util.write_mesh(mpath, msh)
        mpath = ' ' + mpath
        log.info('Mpath: %s' % mpath)
    ppath = _make_pts_input_str(d, pts)
    if grd is not None:
        gpath = d + '/g.grd'
        file_util.write_grd(gpath, grd, world2grid=world2grid)
        gpath = ' ' + gpath + ' -grid_threshold %0.6f' % grid_threshold
    cmd = '%s/gapsview%s%s%s%s' % (path_util.gaps_path(), mpath, ppath, gpath,
                                   init_camera)
    log.info(cmd)
    sp.check_output(cmd, shell=True)
Beispiel #2
0
def make_metrics(proto):
  """Returns a single-element list containing a dictionary of metrics."""
  key, s = proto
  p = results_pb2.Results.FromString(s)
  mesh_path = f"{FLAGS.occnet_dir}{key.replace('test/', '')}.ply"
  log.warning('Mesh path: %s' % mesh_path)
  try:
    mesh = file_util.read_mesh(mesh_path)
    _, synset, mesh_hash = key.split('/')
    if FLAGS.transform:
      ex = example.InferenceExample('test', synset, mesh_hash)
      tx = ex.gaps_to_occnet
      mesh.apply_transform(tx)
    log.info('Succeeded on %s' % mesh_path)
  # pylint:disable=broad-except
  except Exception as e:
    # pylint:enable=broad-except
    log.error(f"Couldn't load {mesh_path}, skipping due to {repr(e)}.")
    return []

  gt_mesh = mesh_util.deserialize(p.gt_mesh)
  dir_out = FLAGS.occnet_dir + '/metrics-out-gt/%s' % key
  if not file_util.exists(dir_out):
    file_util.makedirs(dir_out)
  file_util.write_mesh(f'{dir_out}gt_mesh.ply', gt_mesh)
  file_util.write_mesh(f'{dir_out}occnet_pred.ply', mesh)

  nc, fst, fs2t, chamfer = metrics.all_mesh_metrics(mesh, gt_mesh)
  return [{
      'key': key,
      'Normal Consistency': nc,
      'F-Score (tau)': fst,
      'F-Score (2*tau)': fs2t,
      'Chamfer': chamfer,
  }]
Beispiel #3
0
def make_metrics(proto):
  """Builds a dictionary containing proto elements."""
  key, s = proto
  p = results_pb2.Results.FromString(s)
  mesh_path = FLAGS.occnet_dir + key.replace('test/', '') + '.ply'
  log.warning('Mesh path: %s' % mesh_path)
  try:
    mesh = file_util.read_mesh(mesh_path)
    if FLAGS.transform:
      # TODO(ldif-user) Set up the path to the transformation:
      tx_path = 'ROOT_DIR/%s/occnet_to_gaps.txt' % key
      occnet_to_gaps = file_util.read_txt_to_np(tx_path).reshape([4, 4])
      gaps_to_occnet = np.linalg.inv(occnet_to_gaps)
      mesh.apply_transform(gaps_to_occnet)
  # pylint: disable=broad-except
  except Exception as e:
    # pylint: enable=broad-except
    log.error("Couldn't load %s, skipping due to %s." % (mesh_path, repr(e)))
    return []

  gt_mesh = mesh_util.deserialize(p.gt_mesh)
  dir_out = FLAGS.occnet_dir + '/metrics-out-gt/%s' % key
  if not file_util.exists(dir_out):
    file_util.makedirs(dir_out)
  file_util.write_mesh(f'{dir_out}gt_mesh.ply', gt_mesh)
  file_util.write_mesh(f'{dir_out}occnet_pred.ply', mesh)

  nc, fst, fs2t, chamfer = metrics.all_mesh_metrics(mesh, gt_mesh)
  return [{
      'key': key,
      'Normal Consistency': nc,
      'F-Score (tau)': fst,
      'F-Score (2*tau)': fs2t,
      'Chamfer': chamfer,
  }]
Beispiel #4
0
def ptsview(pts, mesh=None, camera='fixed'):
    """Interactively visualizes a pointcloud alongside an optional mesh."""
    with py_util.py2_temporary_directory() as d:
        ptspath = _make_pts_input_str(d, pts, allow_none=False)
        init_camera = _setup_cam(camera)
        mshpath = ''
        if mesh:
            mshpath = d + '/m.ply'
            file_util.write_mesh(mshpath, mesh)
            mshpath = ' ' + mshpath
        cmd = '%s/ptsview %s%s%s' % (path_util.gaps_path(), ptspath, mshpath,
                                     init_camera)
        log.info(cmd)
        sp.check_output(cmd, shell=True)
Beispiel #5
0
def mshview(mesh, camera='fixed'):
    """Interactively views a mesh."""
    with py_util.py2_temporary_directory() as d:
        init_camera = _setup_cam(camera)
        if not isinstance(mesh, list):
            mesh = [mesh]
        assert len(mesh) <= 4
        mshpath = ''
        for m, c in zip(mesh, ['m', 'n', 'o', 'p']):
            lpath = f'{d}/{c}.ply'
            mshpath += f' {lpath}'
            file_util.write_mesh(lpath, m)
        cmd = '%s/mshview %s%s' % (path_util.gaps_path(), mshpath, init_camera)
        log.info(cmd)
        sp.check_output(cmd, shell=True)
Beispiel #6
0
def _write_results(proto, xid=None):
    """Writes the prediction, ground truth, and representation to disk."""
    key, s = proto
    p = results_pb2.Results.FromString(s)
    if xid is None:
        dir_out = FLAGS.input_dir + '/extracted/' + key + '/'
    else:
        dir_out = FLAGS.input_dir + '/extracted/XID%i/%s/' % (xid, key)
    file_util.makedirs(dir_out)
    file_util.write_mesh(f'{dir_out}/gt_mesh.ply', p.gt_mesh)
    file_util.write_mesh(f'{dir_out}/pred_mesh.ply', p.mesh)
    file_util.writetxt(f'{dir_out}/sif.txt', p.representation)
    # TODO(ldif-user) Set up the unnormalized2normalized path.
    path_to_tx = '/ROOT_DIR/%s/occnet_to_gaps.txt' % key
    occnet_to_gaps = file_util.read_txt_to_np(path_to_tx).reshape([4, 4])
    pm = mesh_util.deserialize(p.mesh)
    pm.apply_transform(occnet_to_gaps)
    file_util.write_mesh(f'{dir_out}/nrm_pred_mesh.ply', pm)
    gtm = mesh_util.deserialize(p.gt_mesh)
    gtm.apply_transform(occnet_to_gaps)
    file_util.write_mesh(f'{dir_out}/nrm_gt_mesh.ply', gtm)