def adam_spanbaauer(video_pth: str, debug: bool = False): if os.path.exists('../.cache/default_stable_video.avi'): print("Cached Video") out = cv2.VideoCapture('../.cache/default_stable_video.avi') else: # Using defaults stabilizer = VidStab() stabilizer.stabilize(input_path=video_pth, output_path='../.cache/default_stable_video.avi') # Using a specific keypoint detector stabilizer = VidStab(kp_method='ORB') stabilizer.stabilize(input_path=video_pth, output_path='../.cache/ORB_stable_video.avi') # Using a specific keypoint detector and customizing keypoint parameters stabilizer = VidStab(kp_method='FAST', threshold=42, nonmaxSuppression=False) stabilizer.stabilize(input_path=video_pth, output_path='../.cache/FAST_stable_video.avi') out = cv2.VideoCapture('../.cache/default_stable_video.avi') if debug: stabilizer.plot_trajectory() plt.show() stabilizer.plot_transforms() plt.show() generate_frames(out, "adam")
def main(original_video_file, stabilized_video_file): stabilizer = VidStab() stabilizer.stabilize(input_path=original_video_file, output_path=stabilized_video_file) stabilizer.plot_trajectory() plt.show() stabilizer.plot_transforms() plt.show()
def stabilize_video(): stabilizer = VidStab() stabilizer.stabilize(input_path='static/Uploads/file.mp4', output_path='static/Output/stable_video.avi') stabilizer.plot_trajectory() plt.savefig('static/img/plot_trajectory.png') stabilizer.plot_transforms() plt.savefig('static/img/plot_transforms.png') return ('________________Completed convertion_____________')
def vidstab(input_path, output_path, kp_method='GFTT', smoothing_window=30, border_type='black', border_size=0): # stabilizer = VidStab(kp_method='FAST', threshold=42, nonmaxSuppression=False) # Using different parameters stabilizer = VidStab(kp_method=kp_method) # Default stabilizer.stabilize(input_path=input_path, output_path=output_path, smoothing_window=smoothing_window, border_type=border_type, border_size=border_size) stabilizer.plot_trajectory() plt.show() stabilizer.plot_transforms() plt.show() return
# remote_ostrich_vid = 'https://s3.amazonaws.com/python-vidstab/ostrich.mp4' # local_ostrich_vid = '{}/ostrich.mp4'.format(tmp_dir.name) # urlretrieve(remote_ostrich_vid, local_ostrich_vid) # local_vid = local_ostrich_vid remote_skateline_vid = 'https://s3.amazonaws.com/python-vidstab/thrasher.mp4' local_skateline_vid = '{}/skateline.mp4'.format(tmp_dir.name) urlretrieve(remote_skateline_vid, local_skateline_vid) local_vid = local_skateline_vid # set params for test stabilization input_path = local_vid border_type = 'black' border_size = 'auto' layer_func = layer_overlay playback = True stabilizer = VidStab() stabilizer.stabilize(input_path, '{}/stable.avi'.format(tmp_dir.name), border_type=border_type, border_size=border_size, layer_func=layer_func, playback=playback) stabilizer.plot_transforms() plt.show() stabilizer.plot_transforms(radians=True) plt.show()
stabilizer.stabilize(input_path='video_seq_1.avi', output_path='stable_video.avi', border_type='black') stabilizer = VidStab(kp_method='FAST', threshold=42, nonmaxSuppression=False) stabilizer.stabilize(input_path='video_seq_1.avi', output_path='stable_video.avi', border_type='black', border_size=100) ############################################## #Plotting frame to frame transformations stabilizer.plot_trajectory() plt.show() stabilizer.plot_transforms() plt.show() ############################################## # filled in borders stabilizer.stabilize(input_path='video_seq_1.avi', output_path='ref_stable_video.avi', border_type='reflect') stabilizer.stabilize(input_path='video_seq_1.avi', output_path='rep_stable_video.avi', border_type='replicate') ################################################# #OBJECT TRACKING TEST FOR VIDEO 2 - COMMENT OUT #################################################
stabilizer.stabilize(input_path=local_vid, output_path=stab_local_vid,smoothing_window=args.smoothing_window,playback=True,border_type='replicate',max_frames=args.max_frames) sys.path.append('/home/som/code/Video-Stabilization/src/functs/') from stabFuncts import * # ITF ITF_crop_flag = False if args.live: local_vid = stab_local_vid[:-4]+'_input.avi' print("ITF of input video", getITF(local_vid,crop=ITF_crop_flag)) print("ITF of stabilized video", getITF(stab_local_vid,crop=ITF_crop_flag)) os.system("python Movie2Frame.py --in-file-name {} --max-frames 10 --write-gray".format(local_vid.split('/')[-1])) frame_filename=local_vid[:-4]+'/frame8_'+local_vid[:-4].split('/')[-1]+'.jpg' print("filename of frame of input video:",frame_filename) ref_img = cv2.imread(frame_filename) avg_input_filename=stab_local_vid[:-4]+'_averaged_input.png' print("filename of avg input image:",avg_input_filename) avg_input_img=cv2.imread(avg_input_filename) avg_stab_filename=stab_local_vid[:-4]+'_averaged.png' print("filename of average stabilized image:",avg_stab_filename) avg_stab_img=cv2.imread(avg_stab_filename) print("PSNR of avg input video vs. frame 0:",getPSNR(ref_img,avg_input_img)) print("PSNR of avg stabilized video vs. frame 0:",getPSNR(ref_img,avg_stab_img)) stabilizer.plot_trajectory() plt.show() stabilizer.plot_transforms() plt.show()