def create_stitched_video_from_scratch(fnString, pos): stores = (fnString + '.21990443', fnString + '.21990445', fnString + '.21990447', fnString + '.21990449') cams_stores = {} for fn in stores: store = new_for_filename(op.join(BASE_DATA, fn)) print store.full_path nFrames = store.frame_count cams_stores[get_store_camera_serial(store)] = store sorted_stores = [cams_stores[i] for i in best_order] undistortions = [Undistort(i) for i in sorted_stores] aligned = StoreAligner(*sorted_stores) aligned.extract_common_frames(StoreAligner.MISSING_POLICY_DROP) if args.truncate == True: suffix = '.partial_stitch' aligned._fns = aligned._fns[ 2000:5000] # THIS IS HOW WE TRUNCATE. #FIXME hardcoded cut elif args.truncate == False: suffix = '.stitched' if not os.path.exists(fnString + suffix): os.mkdir(fnString + suffix) out = imgstore.new_for_format('avc1/mp4', mode='w', basedir=fnString + suffix, imgshape=s.panorama_shape, imgdtype='uint8', chunksize=500) for n, (imgs, (fn, ts)) in enumerate(aligned.iter_imgs(return_times=True)): _imgs = [] for i in range(len(undistortions)): _imgs.append(undistortions[i].undistort(imgs[i])) #with silence_stdout(): ok, img = s.stitch_images(*[ensure_color(i) for i in _imgs]) assert ok out.add_image(img, fn, ts) printProgressBar(n, nFrames, prefix='Stitching progress:', stdoutpos=pos) out.close() return
def create_stitched_video_from_scratch(path): DIRECTORY, fnString = path.rsplit('/', 1) DIRECTORY = DIRECTORY + '/' stores = (fnString + '.21990443', fnString + '.21990445', fnString + '.21990447', fnString + '.21990449') cams_stores = {} for fn in stores: store = new_for_filename(op.join(BASE_DATA, fn)) print store.full_path cams_stores[get_store_camera_serial(store)] = store sorted_stores = [cams_stores[i] for i in best_order] undistortions = [Undistort(i) for i in sorted_stores] aligned = StoreAligner(*sorted_stores) aligned.extract_common_frames(StoreAligner.MISSING_POLICY_DROP) if not os.path.exists(DIRECTORY + fnString + '.stitched'): os.mkdir(DIRECTORY + fnString + '.stitched') """ out = new_for_format('avc1/mp4', DIRECTORY + fnString + '.stitched/metadata.yaml', imgshape=s.panorama_shape, imgdtype=np.uint8) """ out = imgstore.new_for_format('avc1/mp4', mode='w', basedir=DIRECTORY + fnString + '.stitched', imgshape=s.panorama_shape, imgdtype='uint8', chunksize=500) for n, (imgs, (fn, ts)) in enumerate(aligned.iter_imgs(return_times=True)): _imgs = [] for i in range(len(undistortions)): _imgs.append(undistortions[i].undistort(imgs[i])) ok, img = s.stitch_images(*[ensure_color(i) for i in _imgs]) assert ok out.add_image(img, fn, ts) out.close() return
def create_stitched_video_from_undistorted(fnString): stores = (fnString + '.21990443_undistorted', fnString + '.21990445_undistorted', fnString + '.21990447_undistorted', fnString + '.21990449_undistorted') cams_stores = {} for fn in stores: store = new_for_filename(op.join(BASE_DATA, fn)) print store.full_path cams_stores[get_store_camera_serial(store)] = store sorted_stores = [cams_stores[i] for i in best_order] aligned = StoreAligner(*sorted_stores) aligned.extract_common_frames(StoreAligner.MISSING_POLICY_DROP) if not os.path.exists(BASE_DATA + fnString + '.stitched'): os.mkdir(BASE_DATA + fnString + '.stitched') out = imgstore.new_for_format('avc1/mp4', mode='w', basedir=BASE_DATA + fnString, imgshape=s.panorama_shape, imgdtype='uint8', chunksize=500) for n, (fn, imgs) in enumerate(aligned.iter_imgs()): ok, img = s.stitch_images(*[ensure_color(i) for i in imgs]) assert ok out.add_image(img, fn, 0) print n out.close() return
else: calibs = ('stitch09_20180910_165817.21990443_undistorted', 'stitch09_20180910_165817.21990447_undistorted', 'stitch09_20180910_165817.21990445_undistorted', 'stitch09_20180910_165817.21990449_undistorted') cams_imgs = {} # load the first frame for the calibration for fn in calibs: with new_for_filename(op.join(BASE_CALIB, fn)) as store: camera_serial = get_store_camera_serial(store) img, _ = store.get_image(frame_number=None, exact_only=True, frame_index=0) cams_imgs[camera_serial] = ensure_color(img) sorted_imgs = [cams_imgs[i] for i in best_order] s = Stitcher(use_gpu=True, estimator_type="homography", matcher_type="affine", warp_type="plane") # s.enable_exposure_compensation('gain_blocks') # s.enable_seam_finding('gc_color') #with silence_stdout(): ok = s.load_calibration(*sorted_imgs) assert ok