def test_multicamgrablabeler(): """Generate simulate data_collection data and run calibrator.""" import infer_sequence base_dir = 'data/batch2/test_data' labeler = MultiCamGrabLabeler('data/batch3') for i in range(0, 13): filename = str(10000000 + i + 1)[1:] + '.jpg' cam_data = { 'cam1_color_file': os.path.join(base_dir, '4', filename), 'cam1_dept_file': os.path.join(base_dir, '6', filename), 'cam2_color_file': os.path.join(base_dir, '5', filename), 'cam2_dept_file': os.path.join(base_dir, '7', filename), 'xeye_image': [ os.path.join(base_dir, '0', filename), os.path.join(base_dir, '1', filename), os.path.join(base_dir, '2', filename), os.path.join(base_dir, '3', filename), ] } labeler.add_files(cam_data) results = labeler.gen_label() if not results: continue images = [] for r in results: images.extend(r['images']) infer_sequence.show_multi_images(images, resize_ratio=0.5, cols=4)
def rerun_multicamgrablabeler(base_dir, num): """Generate simulate data_collection data and run calibrator.""" import infer_sequence # base_dir = 'data/batch4' collection_dir = 'test_data' labeler = MultiCamGrabLabeler(base_dir).init_from_test_data(collection_dir) num = int(num) for i in range(2, num): results = labeler.gen_label(counter=i) images = [] for r in results: images.extend(r['images']) infer_sequence.show_multi_images(images, resize_ratio=0.5, cols=2)
def convert_to_airupdate(base_dir, num, output_arg): from align_all_sensor import MultiCamGrabLabeler import infer_sequence from kvtools import append_kv from kvtools import convert_to_stream_out from attrs_utils import to_bytes # base_dir = 'data/batch4' collection_dir = 'test_data' labeler = MultiCamGrabLabeler(base_dir).init_from_test_data(collection_dir) out = convert_to_stream_out(output_arg) num = int(num) for i in range(2, num): results = labeler.gen_label(counter=i) images = [] for r in results: images.extend(r['images']) infer_sequence.show_multi_images(images, resize_ratio=0.5, cols=2) f = open( os.path.join(base_dir, 'test_data', '0', str(10000000 + i)[1:] + '.txt')) product_id = f.read().strip() for res in results: for r in res['combined']: print('r:', r.keys()) x, y, degree = r['rot_rect'] start_frame = AirProductFrame(filepath=r['rgb0'], data=open(r['rgb0'], 'rb').read()) end_frame = AirProductFrame(filepath=r['rgb1'], data=open(r['rgb1'], 'rb').read()) rs_info = RealsenseAssistInfo( poly=r['poly'], sum_depth_diff=r['sum_depth_diff'], rect=r['rect'], rot_rect=(x[0], x[1], y[0], y[1], degree), region=r['region'], contour=r['contour']) action = 1 if r['sum_depth_diff'] > 0 else -1 record_id = base_dir + '_' + str(i) airup = AirRecordOfBuildSearchUpdate(start_frame=start_frame, end_frame=end_frame, goods_num=action, action=action, product_id=product_id, record_id=record_id, key=record_id, rs_assist_info=rs_info) v = to_bytes(airup) append_kv(airup.key.encode('utf-8'), v, out)
def show_images(self, resize_ratio=0.5, cols=4): import cv2 import infer_sequence print(self.counter) for i in range(self.counter): images = [] for j in self.rgb_cam_list: n = str(10000000 + i + 1)[1:] path = os.path.join(self.calib_data_dir, str(j), 'cam0', n) if not os.path.exists(path + '.jpg'): path = path + '.png' else: path = path + '.jpg' print(path) images.append(cv2.imread(path)) infer_sequence.show_multi_images(images, resize_ratio, cols)
def show_images(self, images, resize_ratio=0.5, cols=2): import infer_sequence logger.info('show image. image size: {}'.format(len(images))) return infer_sequence.show_multi_images(images, resize_ratio, cols)