order = order[inds + 1] #list the score(delete scores the over thresh) return keep #the score list #dataset = 'hinterstoisser' # dataset = 'tless' # dataset = 'tudlight' # dataset = 'rutgers' # dataset = 'tejani' dataset = 'doumanoglou' # dataset = 'toyotalight' #mode = 'render_train' mode = 'test' dp = get_dataset_params(dataset) detector = linemodLevelup_pybind.Detector(16, [4, 8], 8) # min features; pyramid strides; num clusters obj_ids = [] # for each obj obj_ids_curr = range(1, dp['obj_count'] + 1) if obj_ids: obj_ids_curr = set(obj_ids_curr).intersection(obj_ids) scene_ids = [] # for each obj im_ids = [] # obj's img gt_ids = [] # multi obj in one img scene_ids_curr = range(1, dp['scene_count'] + 1) if scene_ids: scene_ids_curr = set(scene_ids_curr).intersection(scene_ids) # mm
test_type = info[2] if len(info) > 2 else '' # Select data type if dataset == 'tless': cam_type = test_type if error_type in ['adi', 'add']: model_type = 'cad_subdivided' else: model_type = 'cad' else: model_type = '' cam_type = '' # Load dataset parameters dp = get_dataset_params(dataset, model_type=model_type, test_type=test_type, cam_type=cam_type) # Load object models if error_type in ['vsd', 'add', 'adi', 'cou']: print('Loading object models...') models = {} for obj_id in range(1, dp['obj_count'] + 1): models[obj_id] = inout.load_ply(dp['model_mpath'].format(obj_id)) # Directories with results for individual scenes scene_dirs = sorted([ d for d in glob.glob(os.path.join(result_path, '*')) if os.path.isdir(d) ])
import os import sys import glob import math import matplotlib.pyplot as plt import numpy as np import yaml sys.path.append(os.path.abspath('..')) from pysixd import inout, misc, transform, renderer import hinter_flip from params.dataset_params import get_dataset_params par = get_dataset_params('hinterstoisser') base_path = '/local/datasets/tlod/hinterstoisser/' rgb_mpath = base_path + 'test/02/rgb/{:04d}.png' model_mpath = base_path + 'models/obj_{:02d}.ply' # Already transformed pose_mpath = '/local/datasets/tlod/dresden/occlusion/poses/{}/info_{:05d}.txt' scene_gt_path = base_path + 'test/02/scene_gt_brachmann.yml' obj_names_id_map = { 'Ape': 1, 'Can': 5, 'Cat': 6, 'Driller': 8, 'Duck': 9, 'Eggbox': 10, 'Glue': 11,
azimuth_range = (0, 2 * math.pi) elev_range = (-0.4363, 0.5 * math.pi) # (-25, 90) [deg] elif dataset == 'tless': # Range of object distances in test images: 649.89 - 940.04 mm radii = [650] # Radii of the view sphere [mm] # radii = range(500, 1101, 100) # [mm] azimuth_range = (0, 2 * math.pi) elev_range = (-0.5 * math.pi, 0.5 * math.pi) model_type = 'reconst' cam_type = 'primesense' par = get_dataset_params(dataset, model_type=model_type, cam_type=cam_type) # Objects to render obj_ids = range(1, par['obj_count'] + 1) # Minimum required number of views on the whole view sphere. The final number of # views depends on the sampling method. min_n_views = 1000 clip_near = 10 # [mm] clip_far = 10000 # [mm] ambient_weight = 0.8 # Weight of ambient light [0, 1] shading = 'phong' # 'flat', 'phong' # Super-sampling anti-aliasing (SSAA) # https://github.com/vispy/vispy/wiki/Tech.-Antialiasing
# Calculates distances of objects from camera in test images of the selected # dataset. import os import sys import math import numpy as np import matplotlib.pyplot as plt sys.path.append(os.path.abspath('..')) from pysixd import inout from params.dataset_params import get_dataset_params # par = get_dataset_params('hinterstoisser') # par = get_dataset_params('tejani') par = get_dataset_params('rutgers') # par = get_dataset_params('tudlight') scene_ids = range(1, par['scene_count'] + 1) obj_dists = [] azimuths = [] elevs = [] ims_count = 0 for scene_id in scene_ids: print('Processing scene: ' + str(scene_id)) scene_gt = inout.load_gt(par['scene_gt_mpath'].format(scene_id)) ims_count += len(scene_gt) for im_id, im_gts in scene_gt.items(): for im_gt in im_gts: if scene_id == 2 and im_gt['obj_id'] != 2:
# Author: Tomas Hodan ([email protected]) # Center for Machine Perception, Czech Technical University in Prague import os import sys import glob import matplotlib.pyplot as plt import numpy as np import yaml sys.path.append(os.path.abspath('..')) from pysixd import inout, misc, renderer from params.dataset_params import get_dataset_params par = get_dataset_params('tejani') base_path = '/local/datasets/tlod/imperial/tejani/' rgb_in_mpath = base_path + 'orig/test/scene_{:02d}/RGB/img_{:03d}.png' depth_in_mpath = base_path + 'orig/test/scene_{:02d}/Depth/img_{:03d}.png' pose_mpath = base_path + 'orig/annotation_new_models/scene_{:02d}/poses{}.txt' model_mpath = base_path + 'models/obj_{:02d}.ply' bbox_cens_path = base_path + 'bbox_cens.yml' scene_info_mpath = base_path + 'test/{:02d}/info.yml' scene_gt_mpath = base_path + 'test/{:02d}/gt.yml' rgb_out_mpath = base_path + 'test/{:02d}/rgb/{:04d}.png' depth_out_mpath = base_path + 'test/{:02d}/depth/{:04d}.png' # scene_ids = range(1, 7)
# Matching estimated poses to the GT poses #------------------------------------------------------------------------------- for error_path in error_paths: print('Processing: ' + error_path) # Parse info about the errors from the folder names error_sign = os.path.basename(error_path) error_type = error_sign.split('_')[0].split('=')[1] n_top = int(error_sign.split('_')[1].split('=')[1]) res_sign = os.path.basename(os.path.dirname(error_path)).split('_') method = res_sign[0] dataset = res_sign[1] test_type = res_sign[2] if len(res_sign) > 3 else '' # Load dataset parameters dp = get_dataset_params(dataset, test_type=test_type) obj_ids = range(1, dp['obj_count'] + 1) scene_ids = range(1, dp['scene_count'] + 1) # Set threshold of correctness (might be different for each object) error_threshs = {} if error_type in ['add', 'adi']: # Relative to object diameter models_info = inout.load_yaml(dp['models_info_path']) for obj_id in obj_ids: obj_diameter = models_info[obj_id]['diameter'] error_threshs[ obj_id] = error_thresh_fact[error_type] * obj_diameter else: # The same threshold for all objects for obj_id in obj_ids:
dataset = info[1] test_type = info[2] if len(info) > 2 else '' # Select data type if dataset == 'tless': cam_type = test_type if error_type in ['adi', 'add']: model_type = 'cad_subdivided' else: model_type = 'cad' else: model_type = '' cam_type = '' # Load dataset parameters dp = get_dataset_params(dataset, model_type=model_type, test_type=test_type, cam_type=cam_type) # Load object models if error_type in ['vsd', 'add', 'adi', 'cou']: print('Loading object models...') models = {} for obj_id in range(1, dp['obj_count'] + 1): models[obj_id] = inout.load_ply(dp['model_mpath'].format(obj_id)) # Directories with results for individual scenes scene_dirs = sorted([d for d in glob.glob(os.path.join(result_path, '*')) if os.path.isdir(d)]) for scene_dir in scene_dirs: scene_id = int(os.path.basename(scene_dir))
def main(): # Paths to pose errors (calculated using eval_calc_errors.py) #--------------------------------------------------------------------------- top_level_path = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) dataset = 'hinterstoisser' # dataset = 'tless' # dataset = 'tudlight' # dataset = 'rutgers' # dataset = 'tejani' # dataset = 'doumanoglou' # dataset = 'toyotalight' error_bpath = pjoin(top_level_path, 'eval') error_paths = [ pjoin(error_bpath, 'patch-linemod_' + dataset), # pjoin(error_bpath, 'hodan-iros15_tless_primesense'), ] error_dir = 'error=vsd_ntop=1_delta=15_tau=20_cost=step' for i in range(len(error_paths)): error_paths[i] = os.path.join(error_paths[i], error_dir) # Other paths #--------------------------------------------------------------------------- # Mask of path to the input file with calculated errors errors_mpath = pjoin('{error_path}', 'errors_{scene_id:02d}.yml') # Mask of path to the output file with established matches and calculated scores matches_mpath = pjoin('{error_path}', 'matches_{eval_sign}.yml') scores_mpath = pjoin('{error_path}', 'scores_{eval_sign}.yml') # Parameters #--------------------------------------------------------------------------- use_image_subset = True # Whether to use the specified subset of images require_all_errors = True # Whether to break if some errors are missing visib_gt_min = 0.1 # Minimum visible surface fraction of valid GT pose visib_delta = 15 # [mm] # Threshold of correctness error_thresh = { 'vsd': 0.3, 'cou': 0.5, 'te': 5.0, # [cm] 're': 5.0 # [deg] } # Factor k; threshold of correctness = k * d, where d is the object diameter error_thresh_fact = {'add': 0.1, 'adi': 0.1} # Evaluation #--------------------------------------------------------------------------- for error_path in error_paths: # Parse info about the errors from the folder names error_sign = os.path.basename(error_path) error_type = error_sign.split('_')[0].split('=')[1] n_top = int(error_sign.split('_')[1].split('=')[1]) res_sign = os.path.basename(os.path.dirname(error_path)).split('_') method = res_sign[0] dataset = res_sign[1] test_type = res_sign[2] if len(res_sign) > 3 else '' # Evaluation signature if error_type in ['add', 'adi']: eval_sign = 'thf=' + str(error_thresh_fact[error_type]) else: eval_sign = 'th=' + str(error_thresh[error_type]) eval_sign += '_min-visib=' + str(visib_gt_min) print('--- Processing: {}, {}, {}'.format(method, dataset, error_type)) # Load dataset parameters dp = get_dataset_params(dataset, test_type=test_type) obj_ids = range(1, dp['obj_count'] + 1) scene_ids = range(1, dp['scene_count'] + 1) # Subset of images to be considered if use_image_subset: im_ids_sets = inout.load_yaml(dp['test_set_fpath']) else: im_ids_sets = None # Set threshold of correctness (might be different for each object) error_threshs = {} if error_type in ['add', 'adi']: # Relative to object diameter models_info = inout.load_yaml(dp['models_info_path']) for obj_id in obj_ids: obj_diameter = models_info[obj_id]['diameter'] error_threshs[obj_id] = error_thresh_fact[error_type] *\ obj_diameter else: # The same threshold for all objects for obj_id in obj_ids: error_threshs[obj_id] = error_thresh[error_type] # Go through the test scenes and match estimated poses to GT poses #----------------------------------------------------------------------- matches = [] # Stores info about the matching estimate for each GT for scene_id in scene_ids: # Load GT poses gts = inout.load_gt(dp['scene_gt_mpath'].format(scene_id)) # Load statistics (e.g. visibility fraction) of the GT poses gt_stats_path = dp['scene_gt_stats_mpath'].format( scene_id, visib_delta) gt_stats = inout.load_yaml(gt_stats_path) # Keep the GT poses and their stats only for the selected images if im_ids_sets is not None: im_ids = im_ids_sets[scene_id] gts = {im_id: gts[im_id] for im_id in im_ids} gt_stats = {im_id: gt_stats[im_id] for im_id in im_ids} # Load pre-calculated errors of the pose estimates scene_errs_path = errors_mpath.format(error_path=error_path, scene_id=scene_id) if os.path.isfile(scene_errs_path): errs = inout.load_errors(scene_errs_path) matches += match_poses(gts, gt_stats, errs, scene_id, visib_gt_min, error_threshs, n_top) elif require_all_errors: raise IOError( '{} is missing, but errors for all scenes are required' ' (require_all_results = True).'.format(scene_errs_path)) # Calculate the performance scores #----------------------------------------------------------------------- # Split the dataset of Hinterstoisser to the original LINEMOD dataset # and the Occlusion dataset by TUD (i.e. the extended GT for scene #2) if dataset == 'hinterstoisser': print('-- LINEMOD dataset') eval_sign_lm = 'linemod_' + eval_sign matches_lm = [m for m in matches if m['scene_id'] == m['obj_id']] scores_lm = calc_scores(scene_ids, obj_ids, matches_lm, n_top) # Save scores scores_lm_path = scores_mpath.format(error_path=error_path, eval_sign=eval_sign_lm) inout.save_yaml(scores_lm_path, scores_lm) # Save matches matches_path = matches_mpath.format(error_path=error_path, eval_sign=eval_sign_lm) inout.save_yaml(matches_path, matches_lm) print('-- Occlusion dataset') eval_sign_occ = 'occlusion_' + eval_sign matches_occ = [m for m in matches if m['scene_id'] == 2] scene_ids_occ = [2] obj_ids_occ = [1, 2, 5, 6, 8, 9, 10, 11, 12] scores_occ = calc_scores(scene_ids_occ, obj_ids_occ, matches_occ, n_top) # Save scores scores_occ_path = scores_mpath.format(error_path=error_path, eval_sign=eval_sign_occ) inout.save_yaml(scores_occ_path, scores_occ) # Save matches matches_path = matches_mpath.format(error_path=error_path, eval_sign=eval_sign_occ) inout.save_yaml(matches_path, matches_occ) else: scores = calc_scores(scene_ids, obj_ids, matches, n_top) # Save scores scores_path = scores_mpath.format(error_path=error_path, eval_sign=eval_sign) inout.save_yaml(scores_path, scores) # Save matches matches_path = matches_mpath.format(error_path=error_path, eval_sign=eval_sign) inout.save_yaml(matches_path, matches) print('Done.')
Home - view all objects """ import os import sys import numpy as np sixd_toolkit_path = '/home/tom/th_data/cmp/projects/sixd/sixd_toolkit' sys.path.append(os.path.abspath(sixd_toolkit_path)) from pysixd import inout, misc, transform # Dataset parameters from params.dataset_params import get_dataset_params # par = get_dataset_params('hinterstoisser') # par = get_dataset_params('tejani') par = get_dataset_params('doumanoglou') # par = get_dataset_params('tudlight') # Path to a 3D model of the scene #scene_model_mpath = None ref_im_ind = 0 scene_gt = {} scene_info = {} bpy = None # pointer to blender's data structure def init(bpy_in): """ Initializes Blender project. """ print('Init...')
axisPoints, _ = cv2.projectPoints(points, rotV, t, K, (0, 0, 0, 0)) img = cv2.line(img, tuple(axisPoints[3].ravel()), tuple(axisPoints[0].ravel()), (255,0,0), 3) img = cv2.line(img, tuple(axisPoints[3].ravel()), tuple(axisPoints[1].ravel()), (0,255,0), 3) img = cv2.line(img, tuple(axisPoints[3].ravel()), tuple(axisPoints[2].ravel()), (0,0,255), 3) return img # dataset = 'hinterstoisser' # dataset = 'tless' # dataset = 'tudlight' # dataset = 'rutgers' # dataset = 'tejani' dataset = 'doumanoglou' # dataset = 'toyotalight' # set ./params/dataset_params common_base_path correctly dp = get_dataset_params(dataset) obj_ids = [1] # for each obj obj_ids_curr = range(1, dp['obj_count'] + 1) if obj_ids: obj_ids_curr = set(obj_ids_curr).intersection(obj_ids) scene_ids = [1] # for each obj im_ids = [] # obj's img gt_ids = [] # multi obj in one img # Whether to consider only the specified subset of images use_image_subset = True
import os import sys import numpy as np import matplotlib.pyplot as plt sys.path.append(os.path.abspath('..')) from pysixd import inout, misc, renderer # Dataset parameters from params.dataset_params import get_dataset_params # par = get_dataset_params('hinterstoisser') # par = get_dataset_params('tejani') # par = get_dataset_params('doumanoglou') # par = get_dataset_params('rutgers') par = get_dataset_params('tudlight') # Select IDs of scenes, images and GT poses to be processed. # Empty list [] means that all IDs will be used. scene_ids = [] im_ids = [] gt_ids = [] # Indicates whether to render RGB image vis_rgb = True # Indicates whether to resolve visibility in the rendered RGB image (using # depth renderings). If True, only the part of object surface, which is not # occluded by any other modeled object, is visible. If False, RGB renderings # of individual objects are blended together. vis_rgb_resolve_visib = False
# Range of object dist. in test images: 509.12 - 1120.41 mm radii = [500] # Radii of the view sphere [mm] # radii = range(500, 1101, 100) azimuth_range = (0, 2 * math.pi) elev_range = (0, 0.5 * math.pi) elif dataset == 'doumanoglou': # Range of object dist. in test images: 454.56 - 1076.29 mm radii = [450] # Radii of the view sphere [mm] # radii = range(500, 1101, 100) azimuth_range = (0, 2 * math.pi) elev_range = (-1.0297, 0.5 * math.pi) # (-59, 90) [deg] par = get_dataset_params(dataset, model_type=model_type, cam_type=cam_type) # Objects to render obj_ids = range(1, par['obj_count'] + 1) # Minimum required number of views on the whole view sphere. The final number of # views depends on the sampling method. min_n_views = 1000 clip_near = 10 # [mm] clip_far = 10000 # [mm] ambient_weight = 0.8 # Weight of ambient light [0, 1] shading = 'phong' # 'flat', 'phong' # Super-sampling anti-aliasing (SSAA) # https://github.com/vispy/vispy/wiki/Tech.-Antialiasing
def main(): # Paths to pose errors (calculated using eval_calc_errors.py) # --------------------------------------------------------------------------- error_bpath = "/path/to/eval/" error_paths = [ pjoin(error_bpath, "hodan-iros15_hinterstoisser"), # pjoin(error_bpath, 'hodan-iros15_tless_primesense'), ] error_dir = "error:vsd_ntop:1_delta:15_tau:20_cost:step" for i in range(len(error_paths)): error_paths[i] = os.path.join(error_paths[i], error_dir) # Other paths # --------------------------------------------------------------------------- # Mask of path to the input file with calculated errors errors_mpath = pjoin("{error_path}", "errors_{scene_id:02d}.yml") # Mask of path to the output file with established matches and calculated scores matches_mpath = pjoin("{error_path}", "matches_{eval_sign}.yml") scores_mpath = pjoin("{error_path}", "scores_{eval_sign}.yml") # Parameters # --------------------------------------------------------------------------- use_image_subset = True # Whether to use the specified subset of images require_all_errors = True # Whether to break if some errors are missing visib_gt_min = 0.1 # Minimum visible surface fraction of valid GT pose visib_delta = 15 # [mm] # Threshold of correctness error_thresh = { "vsd": 0.3, "cou": 0.5, "te": 5.0, "re": 5.0 } # [cm] # [deg] # Factor k; threshold of correctness = k * d, where d is the object diameter error_thresh_fact = {"add": 0.1, "adi": 0.1} # Evaluation # --------------------------------------------------------------------------- for error_path in error_paths: # Parse info about the errors from the folder names error_sign = os.path.basename(error_path) error_type = error_sign.split("_")[0].split(":")[1] n_top = int(error_sign.split("_")[1].split(":")[1]) res_sign = os.path.basename(os.path.dirname(error_path)).split("_") method = res_sign[0] dataset = res_sign[1] test_type = res_sign[2] if len(res_sign) > 3 else "" # Evaluation signature if error_type in ["add", "adi"]: eval_sign = "thf:" + str(error_thresh_fact[error_type]) else: eval_sign = "th:" + str(error_thresh[error_type]) eval_sign += "_min-visib:" + str(visib_gt_min) print("--- Processing: {}, {}, {}".format(method, dataset, error_type)) # Load dataset parameters dp = get_dataset_params(dataset, test_type=test_type) obj_ids = range(1, dp["obj_count"] + 1) scene_ids = range(1, dp["scene_count"] + 1) # Subset of images to be considered if use_image_subset: im_ids_sets = inout.load_yaml(dp["test_set_fpath"]) else: im_ids_sets = None # Set threshold of correctness (might be different for each object) error_threshs = {} if error_type in ["add", "adi"]: # Relative to object diameter models_info = inout.load_yaml(dp["models_info_path"]) for obj_id in obj_ids: obj_diameter = models_info[obj_id]["diameter"] error_threshs[ obj_id] = error_thresh_fact[error_type] * obj_diameter else: # The same threshold for all objects for obj_id in obj_ids: error_threshs[obj_id] = error_thresh[error_type] # Go through the test scenes and match estimated poses to GT poses # ----------------------------------------------------------------------- matches = [] # Stores info about the matching estimate for each GT for scene_id in scene_ids: # Load GT poses gts = inout.load_gt(dp["scene_gt_mpath"].format(scene_id)) # Load statistics (e.g. visibility fraction) of the GT poses gt_stats_path = dp["scene_gt_stats_mpath"].format( scene_id, visib_delta) gt_stats = inout.load_yaml(gt_stats_path) # Keep the GT poses and their stats only for the selected images if im_ids_sets is not None: im_ids = im_ids_sets[scene_id] gts = {im_id: gts[im_id] for im_id in im_ids} gt_stats = {im_id: gt_stats[im_id] for im_id in im_ids} # Load pre-calculated errors of the pose estimates scene_errs_path = errors_mpath.format(error_path=error_path, scene_id=scene_id) if os.path.isfile(scene_errs_path): errs = inout.load_errors(scene_errs_path) matches += match_poses(gts, gt_stats, errs, scene_id, visib_gt_min, error_threshs, n_top) elif require_all_errors: raise IOError( "{} is missing, but errors for all scenes are required" " (require_all_results = True).".format(scene_errs_path)) # Calculate the performance scores # ----------------------------------------------------------------------- # Split the dataset of Hinterstoisser to the original LINEMOD dataset # and the Occlusion dataset by TUD (i.e. the extended GT for scene #2) if dataset == "hinterstoisser": print("-- LINEMOD dataset") eval_sign_lm = "linemod_" + eval_sign matches_lm = [m for m in matches if m["scene_id"] == m["obj_id"]] scores_lm = calc_scores(scene_ids, obj_ids, matches_lm, n_top) # Save scores scores_lm_path = scores_mpath.format(error_path=error_path, eval_sign=eval_sign_lm) inout.save_yaml(scores_lm_path, scores_lm) # Save matches matches_path = matches_mpath.format(error_path=error_path, eval_sign=eval_sign_lm) inout.save_yaml(matches_path, matches_lm) print("-- Occlusion dataset") eval_sign_occ = "occlusion_" + eval_sign matches_occ = [m for m in matches if m["scene_id"] == 2] scene_ids_occ = [2] obj_ids_occ = [1, 2, 5, 6, 8, 9, 10, 11, 12] scores_occ = calc_scores(scene_ids_occ, obj_ids_occ, matches_occ, n_top) # Save scores scores_occ_path = scores_mpath.format(error_path=error_path, eval_sign=eval_sign_occ) inout.save_yaml(scores_occ_path, scores_occ) # Save matches matches_path = matches_mpath.format(error_path=error_path, eval_sign=eval_sign_occ) inout.save_yaml(matches_path, matches_occ) else: scores = calc_scores(scene_ids, obj_ids, matches, n_top) # Save scores scores_path = scores_mpath.format(error_path=error_path, eval_sign=eval_sign) inout.save_yaml(scores_path, scores) # Save matches matches_path = matches_mpath.format(error_path=error_path, eval_sign=eval_sign) inout.save_yaml(matches_path, matches) print("Done.")