def detect_chessboard(path, out, pattern, gridSize): create_chessboard(path, pattern, gridSize) dataset = ImageFolder(path, annot='chessboard') dataset.isTmp = False for i in tqdm(range(len(dataset))): imgname, annotname = dataset[i] # detect the 2d chessboard img = cv2.imread(imgname) annots = read_json(annotname) show = findChessboardCorners(img, annots, pattern) save_json(annotname, annots) if show is None: continue outname = join(out, imgname.replace(path + '/images/', '')) os.makedirs(os.path.dirname(outname), exist_ok=True) cv2.imwrite(outname, show)
def detect_chessboard_sequence(path, out, pattern, gridSize, args): create_chessboard(path, pattern, gridSize, ext=args.ext) subs = sorted(os.listdir(join(path, 'images'))) for sub in subs: dataset = ImageFolder(path, sub=sub, annot='chessboard', ext=args.ext) dataset.isTmp = False nFrames = len(dataset) found = np.zeros(nFrames, dtype=np.bool) visited = np.zeros(nFrames, dtype=np.bool) proposals = [] init_step = args.max_step min_step = args.min_step for nf in range(0, nFrames, init_step): if nf + init_step < len(dataset): proposals.append([nf, nf + init_step]) while len(proposals) > 0: left, right = proposals.pop(0) print('Check [{}, {}]'.format(left, right)) for nf in [left, right]: if not visited[nf]: visited[nf] = True imgname, annotname = dataset[nf] # detect the 2d chessboard img = cv2.imread(imgname) annots = read_json(annotname) show = findChessboardCorners(img, annots, pattern) save_json(annotname, annots) if show is None: if args.debug: print('Cannot find {}'.format(imgname)) found[nf] = False continue found[nf] = True outname = join(out, imgname.replace(path + '/images/', '')) os.makedirs(os.path.dirname(outname), exist_ok=True) cv2.imwrite(outname, show) if not found[left] and not found[right]: continue mid = (left + right) // 2 if mid == left or mid == right: continue if mid - left > min_step: proposals.append((left, mid)) if right - mid > min_step: proposals.append((mid, right))
def annot_example(path): # define datasets dataset = ImageFolder(path) # define visualize vis_funcs = [vis_point, vis_line] # construct annotations annotator = AnnotBase(dataset=dataset, key_funcs={}, vis_funcs=vis_funcs) while annotator.isOpen: annotator.run()
def detect_chessboard(path, out, pattern, gridSize, args): create_chessboard(path, pattern, gridSize, ext=args.ext) dataset = ImageFolder(path, annot='chessboard', ext=args.ext) dataset.isTmp = False if args.silent: trange = range(len(dataset)) else: trange = tqdm(range(len(dataset))) for i in trange: imgname, annotname = dataset[i] # detect the 2d chessboard img = cv2.imread(imgname) annots = read_json(annotname) show = findChessboardCorners(img, annots, pattern) save_json(annotname, annots) if show is None: if args.debug: print('Cannot find {}'.format(imgname)) continue outname = join(out, imgname.replace(path + '/images/', '')) os.makedirs(os.path.dirname(outname), exist_ok=True) cv2.imwrite(outname, show)
def annot_example(path, sub, image, annot, step, args): # define datasets dataset = ImageFolder(path, sub=sub, image=image, annot=annot) key_funcs = { 'v': set_unvisible, 'V': set_unvisible_according_previous, 'f': set_face_unvisible, 'c': check_track, 'm': mirror_keypoints2d, 'M': mirror_keypoints2d_leg, } if args.hrnet: estimator = Estimator() key_funcs['e'] = estimator.detect_with_bbox key_funcs['r'] = estimator.detect_with_bbox90 key_funcs['t'] = estimator.detect_with_bbox180 key_funcs['y'] = estimator.detect_with_bbox270 key_funcs['g'] = estimator.detect_with_previous_slow key_funcs['j'] = estimator.detect_with_previous_mid # callback of bounding box callbacks = [ callback_select_bbox_corner, callback_select_bbox_center, callback_select_joints ] # callback of keypoints # define visualize vis_funcs = [plot_skeleton_factory('body25'), vis_bbox, vis_active_bbox] if args.hand: vis_funcs += [ plot_bbox_factory('bbox_handl2d'), plot_bbox_factory('bbox_handr2d'), plot_bbox_factory('bbox_face2d') ] vis_funcs += [ plot_skeleton_factory('handl'), plot_skeleton_factory('handr'), plot_skeleton_factory('face') ] vis_funcs += [resize_to_screen, plot_text, capture_screen] # construct annotations annotator = AnnotBase(dataset=dataset, key_funcs=key_funcs, vis_funcs=vis_funcs, callbacks=callbacks, name=sub, step=step) while annotator.isOpen: annotator.run()
def annot_example(path, subs, annot, step): for sub in subs: # define datasets dataset = ImageFolder(path, sub=sub, annot=annot) key_funcs = {'t': auto_pose_track} callbacks = [callback_select_bbox_corner, callback_select_bbox_center] # define visualize vis_funcs = [vis_line, plot_bbox_body, vis_active_bbox] # construct annotations annotator = AnnotBase(dataset=dataset, key_funcs=key_funcs, vis_funcs=vis_funcs, callbacks=callbacks, name=sub, step=step) while annotator.isOpen: annotator.run()
def annot_example(path, args): # define datasets calib = Matcher(path, mode=args.mode, args=args) dataset = ImageFolder(path, annot=args.annot) # define visualize vis_funcs = [vis_point, vis_line, calib.vis, resize_to_screen, plot_text] key_funcs = { ' ': calib.add, 'z': calib.add_conf, 'p': calib.add_point_by_2lines, 'c': calib.clear_point, 'C': calib.clear, } # construct annotations annotator = AnnotBase(dataset=dataset, key_funcs=key_funcs, vis_funcs=vis_funcs) while annotator.isOpen: annotator.run()
def annot_example(path, annot, sub=None, step=100): # define datasets dataset = ImageFolder(path, sub=sub, annot=annot) key_funcs = { 'X': get_record_vanish_lines(0), 'Y': get_record_vanish_lines(1), 'Z': get_record_vanish_lines(2), 'k': get_calc_intrinsic('xy'), 'K': get_calc_intrinsic('yz'), 'b': vanish_point_from_body, 'C': clear_vanish_points, 'B': clear_body_points, 'c': copy_edges_from_cache, 'v': copy_edges } # define visualize vis_funcs = [vis_line, plot_skeleton, vis_vanish_lines, plot_text] # construct annotations annotator = AnnotBase(dataset=dataset, key_funcs=key_funcs, vis_funcs=vis_funcs, step=step) annots = annotator.param['annots'] print(sub) annotator.run('X') annotator.run('Y') annotator.run('Z') annotator.run('k') if 'K' in annots.keys() and False: print('\n'.join([ ' '.join(['{:7.2f}'.format(i) for i in row]) for row in annots['K'] ])) return 0 else: print('K is not caculated') while annotator.isOpen: annotator.run() for key in ['vanish_line', 'vanish_point']: edges_cache[key] = annotator.param['annots'][key]
def annot_example(path, annot, sub=None, step=100): # define datasets dataset = ImageFolder(path, sub=sub, annot=annot) key_funcs = { 'X': get_record_vanish_lines(0), 'Y': get_record_vanish_lines(1), 'Z': get_record_vanish_lines(2), 'k': get_calc_intrinsic('xy'), 'K': get_calc_intrinsic('yz'), 'b': vanish_point_from_body, 'C': clear_vanish_points, 'B': clear_body_points, 'c': copy_edges, } # define visualize vis_funcs = [vis_line, plot_skeleton_simple, vis_vanish_lines] # construct annotations annotator = AnnotBase(dataset=dataset, key_funcs=key_funcs, vis_funcs=vis_funcs, step=step) while annotator.isOpen: annotator.run()