def geometric_voting_rel(boxes, wmax, wmin, rtol, intersect_mode, verb=False): global centers, w_max, w_min, radii, r_rel_tol, vote_db, relative_search, verbose relative_search = True vote_db = {} r_rel_tol = rtol w_max = wmax w_min = wmin n = boxes.shape[0] radii = np.zeros(n) center_points = np.zeros((n, 2)) # approximate all radii in pixels for i, box in enumerate(boxes): radii[i] = util.calculate_radius(box) center_points[i] = util.calculate_center(box) centers = center_points # get sorting vector sort = radii.argsort()[::-1] # sort dat shit radii = radii[sort] tuple_generator = combos(np.arange(n), 2) for count, (ci, cj) in enumerate(tuple_generator): # get pair-database indices of pair candidates if intersect_mode: ci_candidates, cj_candidates = search_pair(ci, cj, True) add_votes_to_db(vote_db, ci, ci_candidates) add_votes_to_db(vote_db, cj, cj_candidates) else: ci_d, ci_r, cj_d, cj_r = search_pair(ci, cj, False) add_votes_to_db(vote_db, ci, ci_d) add_votes_to_db(vote_db, ci, ci_r) add_votes_to_db(vote_db, cj, cj_d) add_votes_to_db(vote_db, cj, cj_r) return do_final_validation(), vote_db
def exclusion_by_intersection_rel(boxes, wmax, wmin, rtol, verb=False): global centers, w_max, w_min, radii, r_rel_tol, intersect_db, relative_search, verbose relative_search = True verbose = verb intersect_db = {} r_rel_tol = rtol w_max = wmax w_min = wmin n = boxes.shape[0] radii = np.zeros(n) center_points = np.zeros((n, 2)) # approximate all radii in pixels for i, box in enumerate(boxes): radii[i] = util.calculate_radius(box) center_points[i] = util.calculate_center(box) centers = center_points # get sorting vector sort = radii.argsort()[::-1] # sort dat shit radii = radii[sort] tuple_generator = combos(np.arange(n), 2) for ci, cj in tuple_generator: # get pair-database indices of pair candidates ci_candidates, cj_candidates = search_pair(ci, cj, True) add_ids_to_db(intersect_db, ci, ci_candidates) add_ids_to_db(intersect_db, cj, cj_candidates) return do_final_validation()
def normalize_joints(joint_pos): center_x, center_y = calculate_center(joint_pos) sigma = calculate_sigma(joint_pos) for i in joint_pos.keys(): joint_pos[i][0] = (joint_pos[i][0] - center_x) / sigma joint_pos[i][1] = (joint_pos[i][1] - center_y) / sigma return joint_pos
def measure(anns, kmpp): hdf = pd.HDFStore('crater_database/crater_db.h5', 'r') crater_db = hdf.get('/db') g = len(anns) tuples = combos(np.arange(g), 2) u = 0 v = 0 diff_dist = 0 diff_rad = 0 for a in range(g): box_a = [anns[a]['x1'], anns[a]['y1'], anns[a]['x2'], anns[a]['y2']] pixel_derived_radius = calculate_radius(box_a) * kmpp real_radius = crater_db.loc[crater_db.index[(anns[a]['crater_id'])], 'radius'] d = real_radius / pixel_derived_radius diff_rad += d print('RADIUS DIFF: ', d) v += 1 diff_rad /= v print('########################### RADIUS AVG DIFF: ', diff_rad) for a, b in tuples: u += 1 print('#####################') print('distances between ', anns[a]['crater_id'], ' with ', anns[a]['lat'], anns[a]['lon'], 'and', anns[b]['crater_id'], ' with ', anns[b]['lat'], anns[b]['lon']) hav = calculate_haversine_distance([anns[a]['lat'], anns[a]['lon']], [anns[b]['lat'], anns[b]['lon']]) appr_real = approximate_visual_distance(hav) print('haversine: ', hav) print('approx: ', appr_real) box_a = [anns[a]['x1'], anns[a]['y1'], anns[a]['x2'], anns[a]['y2']] box_b = [anns[b]['x1'], anns[b]['y1'], anns[b]['x2'], anns[b]['y2']] approx_dist_pixels = \ cdist(np.array([calculate_center(box_a)]), np.array([calculate_center(box_b)]))[0][0] appr_img = approx_dist_pixels * kmpp print('approx pixel dist from bounding box: ', approx_dist_pixels, 'approx km dist from bounding box: ', appr_img) print('difference factor: ', appr_img / appr_real) diff_dist += appr_img / appr_real print('#####################', 'DIFF_AVG:', diff_dist / u, '####################') hdf.close()
def update_keypoint_locations(img_lst, joint_lst): new_joint_lst = [] # Iterate over right hand saved images for indx, joint_dict in enumerate(joint_lst): #print('Processing index: ', indx) if indx % 1000 == 0: print("Processed %d images" %indx) # Calculate the center using keypoints center_x, center_y = calculate_center(joint_dict) sigma = calculate_sigma(joint_dict) new_joint_map = update_joint_pos_using_center(img_lst[indx], joint_dict, center_x, center_y, sigma) new_joint_lst.append(new_joint_map) return new_joint_lst
def geometric_voting_abs(boxes, km_pp, r_tol, d_tol, wmax, verb=False): global radius_candidates, rtol, dtol, centers, vote_db, kmpp, w_max, relative_search, verbose relative_search = False vote_db = {} radius_candidates = {} dtol = d_tol rtol = r_tol w_max = wmax kmpp = km_pp n = boxes.shape[0] radii = np.zeros(n) center_points = np.zeros((n, 2)) # calculate all radii and center points for i, box in enumerate(boxes): radii[i] = util.calculate_radius(box) * kmpp center_points[i] = util.calculate_center(box) # get sorting vector sort = radii.argsort()[::-1] # sort dat shit radii = radii[sort] center_points = center_points[sort] center_points *= kmpp centers = center_points # get the radius candidates for c, r in enumerate(radii): radius_candidates[c] = pdb.get_craters_by_real_radius(r, r_tol) tuples = list(combos(np.arange(n), 2)) t = len(tuples) intersect = False for count, (ci, cj) in enumerate(tuples): util.print_progress(count, t, 'Pairs loop', 'complete') ci_candidates, cj_candidates = search_pair(ci, cj, False) vote_db = add_votes_to_db(vote_db, ci, ci_candidates) vote_db = add_votes_to_db(vote_db, cj, cj_candidates) if not intersect: vote_db = add_votes_to_db(vote_db, ci, radius_candidates[ci]) vote_db = add_votes_to_db(vote_db, cj, radius_candidates[cj]) # check_db() return do_final_validation()
def exclusion_by_intersection_abs(boxes, km_pp, r_tol, d_tol, wmax, verb=False): global radius_candidates, rtol, dtol, centers, intersect_db, kmpp, w_max, relative_search, verbose relative_search = False intersect_db = {} radius_candidates = {} dtol = d_tol rtol = r_tol w_max = wmax kmpp = km_pp n = boxes.shape[0] radii = np.zeros(n) center_points = np.zeros((n, 2)) # calculate all radii and center points for i, box in enumerate(boxes): radii[i] = util.calculate_radius(box) * kmpp center_points[i] = util.calculate_center(box) # get sorting vector sort = radii.argsort()[::-1] # sort dat shit radii = radii[sort] center_points = center_points[sort] center_points *= kmpp centers = center_points # get the radius candidates for c, r in enumerate(radii): radius_candidates[c] = pdb.get_craters_by_real_radius(r, r_tol) tuples = list(combos(np.arange(n), 2)) for ci, cj in tuples: ci_candidates, cj_candidates = search_pair(ci, cj, True) add_ids_to_db(intersect_db, ci, ci_candidates) add_ids_to_db(intersect_db, cj, cj_candidates) return do_final_validation()
def draw_bounding_box(img_file, joints): img_dir = "../mpii/images/" img = cv2.imread(img_dir + img_file) center_x, center_y = calculate_center(joints) sigma = calculate_sigma(joints) show_subsection(img, sigma, joints['r_elbow'][0], joints['r_elbow'][1])