def ucf101_stats(save_path, directory=".", filename="ucf101_stats.pkl"): """Generate statistaic for UCF-101 dataset. Paramters --------- save_path : string UCF-101 dataset save path directory : string directory you want to save the stats, in default, it's in current folder filename : string filename you want to save the stats, in default, it's named "ucf101_stats.pkl" Returns ------- A file named with respective filename """ save_path = tools.check_path(save_path) ucf101_stats = {} ucf101_list = [ "ApplyEyeMakeup", "ApplyLipstick", "Archery", "BabyCrawling", "BalanceBeam", "BandMarching", "BaseballPitch", "Basketball", "BasketballDunk", "BenchPress", "Biking", "Billiards", "BlowDryHair", "BlowingCandles", "BodyWeightSquats", "Bowling", "BoxingPunchingBag", "BoxingSpeedBag", "BreastStroke", "BrushingTeeth", "CleanAndJerk", "CliffDiving", "CricketBowling", "CricketShot", "CuttingInKitchen", "Diving", "Drumming", "Fencing", "FieldHockeyPenalty", "FloorGymnastics", "FrisbeeCatch", "FrontCrawl", "GolfSwing", "Haircut", "HammerThrow", "Hammering", "HandstandPushups", "HandstandWalking", "HeadMassage", "HighJump", "HorseRace", "HorseRiding", "HulaHoop", "IceDancing", "JavelinThrow", "JugglingBalls", "JumpRope", "JumpingJack", "Kayaking", "Knitting", "LongJump", "Lunges", "MilitaryParade", "Mixing", "MoppingFloor", "Nunchucks", "ParallelBars", "PizzaTossing", "PlayingCello", "PlayingDaf", "PlayingDhol", "PlayingFlute", "PlayingGuitar", "PlayingPiano", "PlayingSitar", "PlayingTabla", "PlayingViolin", "PoleVault", "PommelHorse", "PullUps", "Punch", "PushUps", "Rafting", "RockClimbingIndoor", "RopeClimbing", "Rowing", "SalsaSpin", "ShavingBeard", "Shotput", "SkateBoarding", "Skiing", "Skijet", "SkyDiving", "SoccerJuggling", "SoccerPenalty", "StillRings", "SumoWrestling", "Surfing", "Swing", "TableTennisShot", "TaiChi", "TennisSwing", "ThrowDiscus", "TrampolineJumping", "Typing", "UnevenBars", "VolleyballSpiking", "WalkingWithDog", "WallPushups", "WritingOnBoard", "YoYo" ] ucf101_stats["ucf101_list"] = ucf101_list for list_name in ucf101_list: fns_temp = glob.glob(save_path + list_name + "/" + "*.avi") file_names = [] for fn in fns_temp: file_names.append(os.path.basename(fn)) ucf101_stats[list_name] = file_names f = file(tools.check_path(directory) + filename, mode="wb") pickle.dump(ucf101_stats, f, protocol=pickle.HIGHEST_PROTOCOL) f.close()
def ucf50_stats(save_path, directory=".", filename="ucf50_stats.pkl"): """Generate statistaic for UCF-50 dataset. Paramters --------- save_path : string UCF-50 dataset save path directory : string directory you want to save the stats, in default, it's in current folder filename : string filename you want to save the stats, in default, it's named "ucf50_stats.pkl" Returns ------- A file named with respective filename """ save_path = tools.check_path(save_path) ucf50_stats = {} ucf50_list = ["BaseballPitch", "Basketball", "BenchPress", "Biking", "Billiards", "BreastStroke", "CleanAndJerk", "Diving", "Drumming", "Fencing", "GolfSwing", "HighJump", "HorseRace", "HorseRiding", "HulaHoop", "JavelinThrow", "JugglingBalls", "JumpRope", "JumpingJack", "Kayaking", "Lunges", "MilitaryParade", "Mixing", "Nunchucks", "PizzaTossing", "PlayingGuitar", "PlayingPiano", "PlayingTabla", "PlayingViolin", "PoleVault", "PommelHorse", "PullUps", "Punch", "PushUps", "RockClimbingIndoor", "RopeClimbing", "Rowing", "SalsaSpin", "SkateBoarding", "Skiing", "Skijet", "SoccerJuggling", "Swing", "TaiChi", "TennisSwing", "ThrowDiscus", "TrampolineJumping", "VolleyballSpiking", "WalkingWithDog", "YoYo"] ucf50_stats["ucf50_list"] = ucf50_list for list_name in ucf50_list: fns_temp = glob.glob(save_path+list_name+"/"+"*.avi") file_names = [] for fn in fns_temp: file_names.append(os.path.basename(fn)) ucf50_stats[list_name] = file_names f = file(tools.check_path(directory)+filename, mode="wb") pickle.dump(ucf50_stats, f, protocol=pickle.HIGHEST_PROTOCOL) f.close()
def ucf50_stats(save_path, directory=".", filename="ucf50_stats.pkl"): """Generate statistaic for UCF-50 dataset. Paramters --------- save_path : string UCF-50 dataset save path directory : string directory you want to save the stats, in default, it's in current folder filename : string filename you want to save the stats, in default, it's named "ucf50_stats.pkl" Returns ------- A file named with respective filename """ save_path = tools.check_path(save_path) ucf50_stats = {} ucf50_list = [ "BaseballPitch", "Basketball", "BenchPress", "Biking", "Billiards", "BreastStroke", "CleanAndJerk", "Diving", "Drumming", "Fencing", "GolfSwing", "HighJump", "HorseRace", "HorseRiding", "HulaHoop", "JavelinThrow", "JugglingBalls", "JumpRope", "JumpingJack", "Kayaking", "Lunges", "MilitaryParade", "Mixing", "Nunchucks", "PizzaTossing", "PlayingGuitar", "PlayingPiano", "PlayingTabla", "PlayingViolin", "PoleVault", "PommelHorse", "PullUps", "Punch", "PushUps", "RockClimbingIndoor", "RopeClimbing", "Rowing", "SalsaSpin", "SkateBoarding", "Skiing", "Skijet", "SoccerJuggling", "Swing", "TaiChi", "TennisSwing", "ThrowDiscus", "TrampolineJumping", "VolleyballSpiking", "WalkingWithDog", "YoYo" ] ucf50_stats["ucf50_list"] = ucf50_list for list_name in ucf50_list: fns_temp = glob.glob(save_path + list_name + "/" + "*.avi") file_names = [] for fn in fns_temp: file_names.append(os.path.basename(fn)) ucf50_stats[list_name] = file_names f = file(tools.check_path(directory) + filename, mode="wb") pickle.dump(ucf50_stats, f, protocol=pickle.HIGHEST_PROTOCOL) f.close()
def tracking_stats(save_path, directory=".", filename="tracking_stats.pkl"): """Generate statistics for Tracking Dataset. You can obtain the dataset from here: http://cmp.felk.cvut.cz/~vojirtom/dataset/ Parameters ---------- save_path : string Tracking dataset save path directory : string directory you want to save the stats, in default, it's in current folder filename : string filename you want to save the stats, in default, it's named "tracking_stats.pkl" Returns ------- A file named with respective filename """ save_path = tools.check_path(save_path) tracking_stats = {} tracking_primary_list = [ "Babenko", "BoBot", "Cehovin", "Ellis_ijcv2011", "Godec", "Kalal", "Kwon", "Kwon_VTD", "Other", "PROST", "Ross", "Thang", "Wang" ] tracking_stats["primary_list"] = tracking_primary_list secondary_list = {} for primary_class in tracking_primary_list: secondary_class = next(os.walk(save_path + primary_class))[1] secondary_list[primary_class] = secondary_class for category in secondary_class: file_path = save_path + primary_class + "/" + category + "/" + "*.*" fns_temp = glob.glob(file_path) file_names = [] for fn in fns_temp: if fn[-4:] != ".txt" and fn[-3:] != ".db": file_names.append(os.path.basename(fn)) tracking_stats[category] = file_names tracking_stats["secondary_list"] = secondary_list f = file(directory + "/" + filename, mode="wb") pickle.dump(tracking_stats, f, protocol=pickle.HIGHEST_PROTOCOL) f.close()
def tracking_stats(save_path, directory=".", filename="tracking_stats.pkl"): """Generate statistics for Tracking Dataset. You can obtain the dataset from here: http://cmp.felk.cvut.cz/~vojirtom/dataset/ Parameters ---------- save_path : string Tracking dataset save path directory : string directory you want to save the stats, in default, it's in current folder filename : string filename you want to save the stats, in default, it's named "tracking_stats.pkl" Returns ------- A file named with respective filename """ save_path = tools.check_path(save_path) tracking_stats = {} tracking_primary_list = ["Babenko", "BoBot", "Cehovin", "Ellis_ijcv2011", "Godec", "Kalal", "Kwon", "Kwon_VTD", "Other", "PROST", "Ross", "Thang", "Wang"] tracking_stats["primary_list"] = tracking_primary_list secondary_list = {} for primary_class in tracking_primary_list: secondary_class = next(os.walk(save_path+primary_class))[1] secondary_list[primary_class] = secondary_class for category in secondary_class: file_path = save_path+primary_class+"/"+category+"/"+"*.*" fns_temp = glob.glob(file_path) file_names = [] for fn in fns_temp: if fn[-4:] != ".txt" and fn[-3:] != ".db": file_names.append(os.path.basename(fn)) tracking_stats[category] = file_names tracking_stats["secondary_list"] = secondary_list f = file(directory+"/"+filename, mode="wb") pickle.dump(tracking_stats, f, protocol=pickle.HIGHEST_PROTOCOL) f.close()
def caltech256_stats(save_path, directory=".", filename="caltech256_stats.pkl"): """Generate statistic for Caltech-256 dataset. Paramters --------- save_path : string Caltech-256 dataset save path directory : string directory you want to save the stats, in default, it's in current folder filename : string filename you want to save the stats, in default, it's named "ucf50_stats.pkl" Returns ------- A file named with respective filename """ if not os.path.isdir(save_path): raise ValueError("Either path is not existed or is a relative path") caltech256_stats = {} caltech256_list = next(os.walk(save_path))[1] caltech256_stats["caltech256_list"] = caltech256_list for list_name in caltech256_list: fns_temp = glob.glob( os.path.join(save_path, list_name) + "/" + "*.jpg") file_names = [] for fn in fns_temp: file_names.append(os.path.basename(fn)) caltech256_stats[list_name] = file_names f = file(tools.check_path(directory) + filename, mode="wb") pickle.dump(caltech256_stats, f, protocol=pickle.HIGHEST_PROTOCOL) f.close()
def caltech256_stats(save_path, directory=".", filename="caltech256_stats.pkl"): """Generate statistic for Caltech-256 dataset. Paramters --------- save_path : string Caltech-256 dataset save path directory : string directory you want to save the stats, in default, it's in current folder filename : string filename you want to save the stats, in default, it's named "ucf50_stats.pkl" Returns ------- A file named with respective filename """ if not os.path.isdir(save_path): raise ValueError("Either path is not existed or is a relative path") caltech256_stats = {} caltech256_list = next(os.walk(save_path))[1] caltech256_stats["caltech256_list"] = caltech256_list for list_name in caltech256_list: fns_temp = glob.glob(os.path.join(save_path, list_name)+"/"+"*.jpg") file_names = [] for fn in fns_temp: file_names.append(os.path.basename(fn)) caltech256_stats[list_name] = file_names f = file(tools.check_path(directory)+filename, mode="wb") pickle.dump(caltech256_stats, f, protocol=pickle.HIGHEST_PROTOCOL) f.close()
def ucf101_stats(save_path, directory=".", filename="ucf101_stats.pkl"): """Generate statistaic for UCF-101 dataset. Paramters --------- save_path : string UCF-101 dataset save path directory : string directory you want to save the stats, in default, it's in current folder filename : string filename you want to save the stats, in default, it's named "ucf101_stats.pkl" Returns ------- A file named with respective filename """ save_path = tools.check_path(save_path) ucf101_stats = {} ucf101_list = ["ApplyEyeMakeup", "ApplyLipstick", "Archery", "BabyCrawling", "BalanceBeam", "BandMarching", "BaseballPitch", "Basketball", "BasketballDunk", "BenchPress", "Biking", "Billiards", "BlowDryHair", "BlowingCandles", "BodyWeightSquats", "Bowling", "BoxingPunchingBag", "BoxingSpeedBag", "BreastStroke", "BrushingTeeth", "CleanAndJerk", "CliffDiving", "CricketBowling", "CricketShot", "CuttingInKitchen", "Diving", "Drumming", "Fencing", "FieldHockeyPenalty", "FloorGymnastics", "FrisbeeCatch", "FrontCrawl", "GolfSwing", "Haircut", "HammerThrow", "Hammering", "HandstandPushups", "HandstandWalking", "HeadMassage", "HighJump", "HorseRace", "HorseRiding", "HulaHoop", "IceDancing", "JavelinThrow", "JugglingBalls", "JumpRope", "JumpingJack", "Kayaking", "Knitting", "LongJump", "Lunges", "MilitaryParade", "Mixing", "MoppingFloor", "Nunchucks", "ParallelBars", "PizzaTossing", "PlayingCello", "PlayingDaf", "PlayingDhol", "PlayingFlute", "PlayingGuitar", "PlayingPiano", "PlayingSitar", "PlayingTabla", "PlayingViolin", "PoleVault", "PommelHorse", "PullUps", "Punch", "PushUps", "Rafting", "RockClimbingIndoor", "RopeClimbing", "Rowing", "SalsaSpin", "ShavingBeard", "Shotput", "SkateBoarding", "Skiing", "Skijet", "SkyDiving", "SoccerJuggling", "SoccerPenalty", "StillRings", "SumoWrestling", "Surfing", "Swing", "TableTennisShot", "TaiChi", "TennisSwing", "ThrowDiscus", "TrampolineJumping", "Typing", "UnevenBars", "VolleyballSpiking", "WalkingWithDog", "WallPushups", "WritingOnBoard", "YoYo"] ucf101_stats["ucf101_list"] = ucf101_list for list_name in ucf101_list: fns_temp = glob.glob(save_path+list_name+"/"+"*.avi") file_names = [] for fn in fns_temp: file_names.append(os.path.basename(fn)) ucf101_stats[list_name] = file_names f = file(tools.check_path(directory)+filename, mode="wb") pickle.dump(ucf101_stats, f, protocol=pickle.HIGHEST_PROTOCOL) f.close()
def dvs_ucf101_exp(ucf101_dir, ucf101_stats_path, recording_save_path, viewer_id, screen_height, screen_width, work_win_scale, bg_color, fps): """Setup an experiment for UCF-101 dataset. Parameters ---------- ucf101_dir : string absolute path of UCF-101 dataset e.g. /home/user/UCF-101 ucf101_stats_path : string path to vot dataset stats recording_save_path : string path to logged recording data viewer_id : int the ID of jAER viewer, for Linux is 1, Mac OS X is 2 screen_height : int height of the screen in pixel screen_width : int width of the screen in pixel work_win_scale : float the scaling factor that calculates working window size bg_color : list background color definition fps : int frame per second while displaying the video, will round to closest number """ ucf101_dir = tools.check_path(ucf101_dir) # fix path if it's not valid # Load UCF-101 stats f = file(ucf101_stats_path, mode="r") ucf101_stats = pickle.load(f) f.close() ucf101_list = ucf101_stats["ucf101_list"] # Set read video function based on platform if _platform == "darwin": read_video = helpers.read_video_macosx elif _platform == "linux2": read_video = helpers.read_video_macosx # Create full background background = np.ones((screen_height, screen_width, 3))*bg_color # Setup OpenCV display window window_title = "DVS-UCF101-EXP" cv2.namedWindow(window_title, cv2.WND_PROP_FULLSCREEN) # Experiment setup calibration # Not without tuning images swin_h, swin_w = helpers.calibration(win_h=screen_height, win_w=screen_width, scale=work_win_scale, window_title=window_title, bg_color=bg_color) # Main routine s = tools.init_dvs() tools.reset_dvs_time(s) for class_name in ucf101_list: if not os.path.exists(str(recording_save_path+class_name+"/")): os.mkdir(str(recording_save_path+class_name+"/")) for video_name in ucf101_stats[class_name]: video_path = str(ucf101_dir+class_name+"/"+video_name) frames, num_frames = read_video(video_path) new_frames = gui.rescale_image_sequence(frames, swin_h, swin_w, bg_color) new_frames = gui.create_border_sequence(new_frames, screen_height, screen_width, bg_color) cv2.imshow(window_title, new_frames[0]) print "[MESSAGE] Adapting video sequence %s" % str(video_name) cv2.waitKey(delay=2000) tools.start_log_dvs(s, recording_save_path, str(class_name+"/"+video_name[:-4]), viewer_id) for i in xrange(num_frames): cv2.imshow(window_title, new_frames[i]) key = cv2.waitKey(delay=int(1000/fps)) & 0xFF if key == 27: cv2.destroyAllWindows() quit() cv2.imshow(window_title, new_frames[-1]) tools.stop_log_dvs(s, viewer_id) print "[MESSAGE] Releasing video sequence %s" % str(video_name) cv2.waitKey(delay=2000) cv2.imshow(window_title, background) cv2.waitKey(delay=1000) tools.reset_dvs_time(s) print "[MESSAGE] Video sequence %s is logged." % str(video_name) # Destory both scoket and opencv window tools.destroy_dvs(s) cv2.destroyAllWindows()
def dvs_ucf50_exp(ucf50_dir, ucf50_stats_path, recording_save_path, viewer_id, screen_height, screen_width, work_win_scale, bg_color, fps): """Setup an experiment for UCF-50 dataset. Parameters ---------- ucf50_dir : string absolute path of UCF-50 dataset e.g. /home/user/UCF50 ucf50_stats_path : string path to vot dataset stats recording_save_path : string path to logged recording data viewer_id : int the ID of jAER viewer, for Linux is 1, Mac OS X is 2 screen_height : int height of the screen in pixel screen_width : int width of the screen in pixel work_win_scale : float the scaling factor that calculates working window size bg_color : list background color definition fps : int frame per second while displaying the video, will round to closest number """ ucf50_dir = tools.check_path(ucf50_dir) # fix path if it's not valid # Load UCF-50 stats f = file(ucf50_stats_path, mode="r") ucf50_stats = pickle.load(f) f.close() ucf50_list = ucf50_stats["ucf50_list"] # Set read video function based on platform if _platform == "darwin": read_video = helpers.read_video_macosx elif _platform == "linux2": read_video = helpers.read_video_macosx # Create full background background = np.ones((screen_height, screen_width, 3))*bg_color # Setup OpenCV display window window_title = "DVS-UCF50-EXP" cv2.namedWindow(window_title, cv2.WND_PROP_FULLSCREEN) # Experiment setup calibration # Not without tuning images swin_h, swin_w = helpers.calibration(win_h=screen_height, win_w=screen_width, scale=work_win_scale, window_title=window_title, bg_color=bg_color) # Main routine s = tools.init_dvs() tools.reset_dvs_time(s) for class_name in ucf50_list: if not os.path.exists(str(recording_save_path+class_name+"/")): os.mkdir(str(recording_save_path+class_name+"/")) for video_name in ucf50_stats[class_name]: video_path = str(ucf50_dir+class_name+"/"+video_name) frames, num_frames = read_video(video_path) new_frames = gui.rescale_image_sequence(frames, swin_h, swin_w, bg_color) new_frames = gui.create_border_sequence(new_frames, screen_height, screen_width, bg_color) cv2.imshow(window_title, new_frames[0]) print "[MESSAGE] Adapting video sequence %s" % str(video_name) cv2.waitKey(delay=2000) tools.start_log_dvs(s, recording_save_path, str(class_name+"/"+video_name[:-4]), viewer_id) for i in xrange(num_frames): cv2.imshow(window_title, new_frames[i]) key = cv2.waitKey(delay=int(1000/fps)) & 0xFF if key == 27: cv2.destroyAllWindows() quit() cv2.imshow(window_title, new_frames[-1]) tools.stop_log_dvs(s, viewer_id) print "[MESSAGE] Releasing video sequence %s" % str(video_name) cv2.waitKey(delay=2000) cv2.imshow(window_title, background) cv2.waitKey(delay=1000) tools.reset_dvs_time(s) print "[MESSAGE] Video sequence %s is logged." % str(video_name) # Destory both scoket and opencv window tools.destroy_dvs(s) cv2.destroyAllWindows()
def dvs_vot_exp(tracking_dir, tracking_stats_path, recording_save_path, viewer_id, screen_height, screen_width, work_win_scale, bg_color, fps): """Setup an experiment for VOT dataset. Parameters ---------- tracking_dir : string absolute path of Tracking dataset e.g. /home/user/vot2015 tracking_stats_path : string path to tracking dataset stats recording_save_path : string path to logged recording data viewer_id : int the ID of jAER viewer, for Linux is 1, Mac OS X is 2 screen_height : int height of the screen in pixel screen_width : int width of the screen in pixel work_win_scale : float the scaling factor that calculates working window size bg_color : list background color definition fps : int frame per second while displaying the video, will round to closest number """ tracking_dir = tools.check_path(tracking_dir) # fix path if it's not valid recording_save_path = tools.check_path(str(recording_save_path)) if not os.path.exists(str(recording_save_path)): os.mkdir(str(recording_save_path)) # Load VOT stats f = file(tracking_stats_path, mode="r") tracking_stats = pickle.load(f) f.close() # primary list pl = tracking_stats["primary_list"] # secondary list sl = tracking_stats["secondary_list"] # Create full background background = np.ones((screen_height, screen_width, 3)) * bg_color # Setup OpenCV display window window_title = "DVS-TRACKING-EXP" cv2.namedWindow(window_title, cv2.WND_PROP_FULLSCREEN) # Experiment setup calibration # Not without tuning images swin_h, swin_w = helpers.calibration(win_h=screen_height, win_w=screen_width, scale=work_win_scale, window_title=window_title, bg_color=bg_color) # Init a general UDP socket s = tools.init_dvs() tools.reset_dvs_time(s) for pcg in pl: # remove sequence Kalal until I got more memory if pcg != "Kalal": for scg in sl[pcg]: print "[MESSAGE] Display video sequence " + scg seq_base_path = tracking_dir + pcg + "/" + scg + "/" frames = [] for fn in tracking_stats[scg]: frames.append(cv2.imread(seq_base_path + fn)) frames = gui.rescale_image_sequence(frames, swin_h, swin_w, bg_color) frames = gui.create_border_sequence(frames, screen_height, screen_width, bg_color) cv2.imshow(window_title, frames[0]) print "[MESSAGE] Adapting video sequence " + scg cv2.waitKey(delay=2000) tools.start_log_dvs(s, recording_save_path, scg, viewer_id) for frame in frames: cv2.imshow(window_title, frame) key = cv2.waitKey(delay=int(1000 / fps)) & 0xFF if key == 27: cv2.destroyAllWindows() quit() cv2.imshow(window_title, frames[-1]) tools.stop_log_dvs(s, viewer_id) print "[MESSAGE] Releasing video sequence " + scg cv2.waitKey(delay=2000) cv2.imshow(window_title, background) cv2.waitKey(delay=1000) tools.reset_dvs_time(s) print "[MESSAGE] Video sequence " + scg + " is logged." # Destory both scoket and opencv window tools.destroy_dvs(s) cv2.destroyAllWindows()
def dvs_vot_exp(vot_dir, vot_stats_path, recording_save_path, viewer_id, screen_height, screen_width, work_win_scale, bg_color, fps): """Setup an experiment for VOT dataset. Parameters ---------- vot_dir : string absolute path of VOT dataset e.g. /home/user/vot2015 vot_stats_path : string path to vot dataset stats recording_save_path : string path to logged recording data viewer_id : int the ID of jAER viewer, for Linux is 1, Mac OS X is 2 screen_height : int height of the screen in pixel screen_width : int width of the screen in pixel work_win_scale : float the scaling factor that calculates working window size bg_color : list background color definition fps : int frame per second while displaying the video, will round to closest number """ vot_dir = tools.check_path(vot_dir) # fix path if it's not valid recording_save_path = tools.check_path(str(recording_save_path)) if not os.path.exists(str(recording_save_path)): os.mkdir(str(recording_save_path)) # Load VOT stats f = file(vot_stats_path, mode="r") vot_stats = pickle.load(f) f.close() vot_list = vot_stats['vot_list'] num_frames = vot_stats['num_frames'] # Load groundtruth and image lists print "[MESSAGE] Loading ground truth and image lists." gts = [] for i in xrange(len(num_frames)): temp_gt = np.loadtxt(vot_dir+vot_list[i]+"/groundtruth.txt", dtype=float, delimiter=",") temp_gt = np.reshape(temp_gt, (temp_gt.shape[0], 4, 2)) gts.append(temp_gt) lists = [] for i in xrange(len(num_frames)): temp_list = tools.create_vot_image_list(vot_dir+vot_list[i]+"/", num_frames[i]) lists.append(temp_list) print "[MESSAGE] Ground truths and image lists are loaded." # Create full background background = np.ones((screen_height, screen_width, 3))*bg_color # Setup OpenCV display window window_title = "DVS-VOT-EXP" cv2.namedWindow(window_title, cv2.WND_PROP_FULLSCREEN) # Experiment setup calibration # Not without tuning images swin_h, swin_w = helpers.calibration(win_h=screen_height, win_w=screen_width, scale=work_win_scale, window_title=window_title, bg_color=bg_color) # Init a general UDP socket s = tools.init_dvs() tools.reset_dvs_time(s) for k in xrange(len(num_frames)): print "[MESSAGE] Display video sequence %i" % (k+1) frames = [] for i in xrange(num_frames[k]): frames.append(cv2.imread(lists[k][i])) new_frames = gui.rescale_image_sequence(frames, swin_h, swin_w, bg_color) # new_frames = gui.draw_poly_box_sequence(new_frames, gts[k]) new_frames = gui.create_border_sequence(new_frames, screen_height, screen_width, bg_color) cv2.imshow(window_title, new_frames[0]) print "[MESSAGE] Adapting video sequence %i" % (k+1) cv2.waitKey(delay=2000) tools.start_log_dvs(s, recording_save_path, vot_list[k], viewer_id) for i in xrange(num_frames[k]): cv2.imshow(window_title, new_frames[i]) key = cv2.waitKey(delay=int(1000/fps)) & 0xFF if key == 27: cv2.destroyAllWindows() quit() cv2.imshow(window_title, new_frames[-1]) tools.stop_log_dvs(s, viewer_id) print "[MESSAGE] Releasing video sequence %i" % (k+1) cv2.waitKey(delay=2000) cv2.imshow(window_title, background) cv2.waitKey(delay=1000) tools.reset_dvs_time(s) print "[MESSAGE] Video sequence %i is logged." % (k+1) # Destory both scoket and opencv window tools.destroy_dvs(s) cv2.destroyAllWindows()
def dvs_vot_exp(vot_dir, vot_stats_path, recording_save_path, viewer_id, screen_height, screen_width, work_win_scale, bg_color, fps): """Setup an experiment for VOT dataset. Parameters ---------- vot_dir : string absolute path of VOT dataset e.g. /home/user/vot2015 vot_stats_path : string path to vot dataset stats recording_save_path : string path to logged recording data viewer_id : int the ID of jAER viewer, for Linux is 1, Mac OS X is 2 screen_height : int height of the screen in pixel screen_width : int width of the screen in pixel work_win_scale : float the scaling factor that calculates working window size bg_color : list background color definition fps : int frame per second while displaying the video, will round to closest number """ vot_dir = tools.check_path(vot_dir) # fix path if it's not valid recording_save_path = tools.check_path(str(recording_save_path)) if not os.path.exists(str(recording_save_path)): os.mkdir(str(recording_save_path)) # Load VOT stats f = file(vot_stats_path, mode="r") vot_stats = pickle.load(f) f.close() vot_list = vot_stats['vot_list'] num_frames = vot_stats['num_frames'] # Load groundtruth and image lists print "[MESSAGE] Loading ground truth and image lists." gts = [] for i in xrange(len(num_frames)): temp_gt = np.loadtxt(vot_dir + vot_list[i] + "/groundtruth.txt", dtype=float, delimiter=",") temp_gt = np.reshape(temp_gt, (temp_gt.shape[0], 4, 2)) gts.append(temp_gt) lists = [] for i in xrange(len(num_frames)): temp_list = tools.create_vot_image_list(vot_dir + vot_list[i] + "/", num_frames[i]) lists.append(temp_list) print "[MESSAGE] Ground truths and image lists are loaded." # Create full background background = np.ones((screen_height, screen_width, 3)) * bg_color # Setup OpenCV display window window_title = "DVS-VOT-EXP" cv2.namedWindow(window_title, cv2.WND_PROP_FULLSCREEN) # Experiment setup calibration # Not without tuning images swin_h, swin_w = helpers.calibration(win_h=screen_height, win_w=screen_width, scale=work_win_scale, window_title=window_title, bg_color=bg_color) # Init a general UDP socket s = tools.init_dvs() tools.reset_dvs_time(s) for k in xrange(len(num_frames)): print "[MESSAGE] Display video sequence %i" % (k + 1) frames = [] for i in xrange(num_frames[k]): frames.append(cv2.imread(lists[k][i])) new_frames = gui.rescale_image_sequence(frames, swin_h, swin_w, bg_color) # new_frames = gui.draw_poly_box_sequence(new_frames, gts[k]) new_frames = gui.create_border_sequence(new_frames, screen_height, screen_width, bg_color) cv2.imshow(window_title, new_frames[0]) print "[MESSAGE] Adapting video sequence %i" % (k + 1) cv2.waitKey(delay=2000) tools.start_log_dvs(s, recording_save_path, vot_list[k], viewer_id) for i in xrange(num_frames[k]): cv2.imshow(window_title, new_frames[i]) key = cv2.waitKey(delay=int(1000 / fps)) & 0xFF if key == 27: cv2.destroyAllWindows() quit() cv2.imshow(window_title, new_frames[-1]) tools.stop_log_dvs(s, viewer_id) print "[MESSAGE] Releasing video sequence %i" % (k + 1) cv2.waitKey(delay=2000) cv2.imshow(window_title, background) cv2.waitKey(delay=1000) tools.reset_dvs_time(s) print "[MESSAGE] Video sequence %i is logged." % (k + 1) # Destory both scoket and opencv window tools.destroy_dvs(s) cv2.destroyAllWindows()