def compute_and_save_flow(video_data): video_dir = "../data/videos/" rgb_dir = "../data/rgb/" flow_dir = "../data/flow/" file_name = video_data["file_name"] rgb_vid_in_p = str(video_dir + file_name + ".mp4") rgb_4d_out_p = str(rgb_dir + file_name + ".npy") flow_4d_out_p = str(flow_dir + file_name + ".npy") if not is_file_here(rgb_vid_in_p): return if is_file_here(rgb_4d_out_p): rgb_4d_out_p = None if is_file_here(flow_4d_out_p): flow_4d_out_p = None if rgb_4d_out_p is None and flow_4d_out_p is None: return # Saves files to disk in format (time, height, width, channel) as numpy array #flow_type = 1 # TVL1 optical flow flow_type = None # will not process optical flow op = OpticalFlow(rgb_vid_in_p=rgb_vid_in_p, rgb_4d_out_p=rgb_4d_out_p, flow_4d_out_p=flow_4d_out_p, clip_flow_bound=20, flow_type=flow_type) op.process()
def video_to_numpy(url, vid_p, rgb_p, file_name): rgb_vid_in_p = vid_p + file_name + ".mp4" rgb_4d_out_p = rgb_p + file_name + ".npy" op = OpticalFlow(rgb_vid_in_p=rgb_vid_in_p, rgb_4d_out_p=rgb_4d_out_p, flow_type=None) op.process()
def main(argv): if len(argv) < 2: print("Usage: python show_video_transforms.py [video_file_path]") return # Read frames op = OpticalFlow(rgb_vid_in_p=argv[1]) rgb_4d = op.vid_to_frames().astype(np.uint8) # ColorJitter need uint8 tl = TestLearner() T = tl.get_transform("rgb", phase="train") rgb_4d = T(rgb_4d).numpy().transpose(1, 2, 3, 0) print(np.amin(rgb_4d), np.amax(rgb_4d)) print(rgb_4d.shape) rgb_4d = cv2.normalize(rgb_4d, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F) op.frames_to_vid(rgb_4d, "../data/transformed.mp4")
import argparse import cv2 import numpy as np from optical_flow.optical_flow import OpticalFlow of = OpticalFlow() def main(): ap = argparse.ArgumentParser() ap.add_argument('-i', '--input', default='videos\\cars.mp4', help='Input video filename') ap.add_argument( '-m', '--mode', default='dense', help= 'optical flow computation mode: sparse (Lucas Kanede), dense (Farneback)' ) args = vars(ap.parse_args()) cap = cv2.VideoCapture(args['input']) if not cap.isOpened(): print('[ERROR] Invalid video.') return # Take first frame and find features in it using ShiTomasi params for detection