def main(): ''' Parse command line arguments and execute the code ''' ######### TENSORBOX PARAMETERS start = time.time() parser = argparse.ArgumentParser() # parser.add_argument('--result_folder', default='summary_result/', type=str) # parser.add_argument('--summary_file', default='results.txt', type=str) parser.add_argument('--output_name', default='output.mp4', type=str) parser.add_argument('--hypes', default='./TENSORBOX/hypes/overfeat_rezoom.json', type=str) parser.add_argument('--weights', default='./TENSORBOX/data/save.ckpt-1250000', type=str) parser.add_argument('--perc', default=100, type=int) parser.add_argument('--path_video', default='ILSVRC2015_val_00004000.mp4', type=str)# required=True, type=str) args = parser.parse_args() # hypes_file = './hypes/overfeat_rezoom.json' # weights_file= './output/save.ckpt-1090000' path_video_folder = os.path.splitext(os.path.basename(args.path_video))[0] pred_idl = './%s/%s_val.idl' % (path_video_folder, path_video_folder) idl_filename=path_video_folder+'/'+path_video_folder+'.idl' frame_tensorbox=[] frame_inception=[] frame_tensorbox, frame_inception = utils_video.extract_frames_incten(args.path_video, args.perc, path_video_folder, idl_filename ) progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()]) for image_path in progress(frame_tensorbox): utils_image.resizeImage(image_path) utils_image.resizeImage(-1) video_info=Utils_Tensorbox.bbox_det_TENSORBOX_multiclass(frame_tensorbox, path_video_folder, args.hypes, args.weights, pred_idl) tracked_video=utils_video.recurrent_track_objects(video_info) # tracked_video=utils_video.track_objects(video_info) # labeled_video=Utils_Imagenet.label_video(tracked_video, frame_inception) labeled_video=Utils_Imagenet.recurrent_label_video(tracked_video, frame_inception) # tracked_video=utils_video.track_objects(video_info) # tracked_video=utils_video.track_and_label_objects(video_info) labeled_frames=utils_video.draw_rectangles(path_video_folder, labeled_video) utils_video.make_tracked_video(args.output_name, labeled_frames) frame.saveVideoResults(idl_filename,labeled_video) # utils_video.make_tracked_video(args.output_name, labeled_video) end = time.time() print("Elapsed Time:%d Seconds"%(end-start)) print("Running Completed with Success!!!")
def main(): ''' Parse command line arguments and execute the code ''' ######### TENSORBOX PARAMETERS start = time.time() parser = argparse.ArgumentParser() # parser.add_argument('--result_folder', default='summary_result/', type=str) # parser.add_argument('--summary_file', default='results.txt', type=str) parser.add_argument('--output_name', default='output.mp4', type=str) parser.add_argument('--hypes', default='./TENSORBOX/hypes/overfeat_rezoom.json', type=str) parser.add_argument('--weights', default='./TENSORBOX/data/save.ckpt-1090000', type=str) parser.add_argument('--perc', default=2, type=int) parser.add_argument('--path_video', required=True, type=str) args = parser.parse_args() # hypes_file = './hypes/overfeat_rezoom.json' # weights_file= './output/save.ckpt-1090000' path_video_folder = os.path.splitext(os.path.basename(args.path_video))[0] pred_idl = './%s/%s_val.idl' % (path_video_folder, path_video_folder) idl_filename = path_video_folder + '/' + path_video_folder + '.idl' frame_list = [] frame_list = Utils_Video.extract_idl_from_frames(args.path_video, args.perc, path_video_folder, 'frames/', idl_filename) progress = progressbar.ProgressBar(widgets=[ progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage(), ' ', progressbar.ETA() ]) for image_path in progress(frame_list): Utils_Image.resizeImage(image_path) Utils_Image.resizeImage(-1) det_frame_list = Utils_Tensorbox.still_image_TENSORBOX_singleclass( frame_list, path_video_folder, args.hypes, args.weights, pred_idl) Utils_Video.make_video_from_list(args.output_name, det_frame_list) end = time.time() print("Elapsed Time:%d Seconds" % (end - start)) print("Running Completed with Success!!!")
def main(): ''' Parse command line arguments and execute the code ''' ######### TENSORBOX PARAMETERS start = time.time() parser = argparse.ArgumentParser() # parser.add_argument('--result_folder', default='summary_result/', type=str) # parser.add_argument('--summary_file', default='results.txt', type=str) parser.add_argument('--output_name', default='output.mp4', type=str) parser.add_argument('--hypes', default='./TENSORBOX/hypes/overfeat_rezoom.json', type=str) parser.add_argument('--weights', default='./TENSORBOX/data/save.ckpt-1090000', type=str) parser.add_argument('--perc', default=2, type=int) parser.add_argument('--path_video', required=True, type=str) args = parser.parse_args() # hypes_file = './hypes/overfeat_rezoom.json' # weights_file= './output/save.ckpt-1090000' path_video_folder = os.path.splitext(os.path.basename(args.path_video))[0] pred_idl = './%s/%s_val.idl' % (path_video_folder, path_video_folder) idl_filename=path_video_folder+'/'+path_video_folder+'.idl' frame_list=[] frame_list = Utils_Video.extract_idl_from_frames(args.path_video, args.perc, path_video_folder, 'frames/', idl_filename ) progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()]) for image_path in progress(frame_list): Utils_Image.resizeImage(image_path) Utils_Image.resizeImage(-1) det_frame_list=Utils_Tensorbox.still_image_TENSORBOX_singleclass( frame_list, path_video_folder, args.hypes, args.weights, pred_idl) Utils_Video.make_video_from_list(args.output_name, det_frame_list) end = time.time() print("Elapsed Time:%d Seconds"%(end-start)) print("Running Completed with Success!!!")
def track_objects(video_info): previous_frame = None previous_num_obj = -1 tracked_video = [] for frame_info in video_info: print("Tracking Frame Nr: %d" % frame_info.frame) print("Len Rects Frame: %d" % len(frame_info.rects)) current_frame = frame.Frame_Info() current_frame = frame_info.duplicate() current_frame.rects = [] if previous_frame is not None: print("Len Previous Rects Frame: %d" % len(previous_frame.rects)) for rect in previous_frame.rects: print(len(current_frame.rects)) current_rect = multiclass_rectangle.pop_max_iou( frame_info.rects, rect) current_rect.load_trackID(rect.trackID) current_frame.append_labeled_rect(current_rect) else: trackID = 1 picked_rect = Utils_Tensorbox.NMS(frame_info.rects) for rect in picked_rect: current_rect = rect.duplicate() current_rect.load_trackID(trackID) current_frame.append_labeled_rect(current_rect) trackID = trackID + 1 previous_frame = current_frame.duplicate() previous_frame.rects = multiclass_rectangle.duplicate_rects( current_frame.rects) print("Current Frame obj:%d" % len(current_frame.rects)) tracked_video.insert(len(tracked_video), current_frame) return tracked_video
def recurrent_track_objects(video_info): previous_frame = None previous_num_obj = -1 tracked_video = [] deltas_video = [] deltas_frame = [] dx1, dx2, dy1, dy2 = 0, 0, 0, 0 for frame_info in video_info: print("Tracking Frame Nr: %d" % frame_info.frame) print("Len Rects Frame: %d" % len(frame_info.rects)) current_frame = frame.Frame_Info() current_frame = frame_info.duplicate() current_frame.rects = [] if previous_frame is not None: deltas_frame = [] if frame_info.frame > 1: print("Len Previous Rects Frame: %d" % len(previous_frame.rects)) rect_idx = 0 for rect in previous_frame.rects: print(len(current_frame.rects)) rect.add_delta( deltas_video[frame_info.frame - 2][rect_idx][0], deltas_video[frame_info.frame - 2][rect_idx][1], deltas_video[frame_info.frame - 2][rect_idx][2], deltas_video[frame_info.frame - 2][rect_idx][3]) current_rect = multiclass_rectangle.pop_max_iou( frame_info.rects, rect) if current_rect is not None: current_rect.load_trackID(rect.trackID) current_rect.check_rects_motion( frame_info.filename, rect, deltas_video[frame_info.frame - 2][rect_idx][0], deltas_video[frame_info.frame - 2][rect_idx][1], deltas_video[frame_info.frame - 2][rect_idx][2], deltas_video[frame_info.frame - 2][rect_idx][3]) current_frame.append_labeled_rect(current_rect) dx1 = current_rect.x1 - rect.x1 dx2 = current_rect.x2 - rect.x2 dy1 = current_rect.y1 - rect.y1 dy2 = current_rect.y2 - rect.y2 deltas_frame.append((dx1, dx2, dy1, dy2)) else: break else: print("Len Previous Rects Frame: %d" % len(previous_frame.rects)) for rect in previous_frame.rects: print(len(current_frame.rects)) current_rect = multiclass_rectangle.pop_max_iou( frame_info.rects, rect) if current_rect is not None: dx1 = current_rect.x1 - rect.x1 dx2 = current_rect.x2 - rect.x2 dy1 = current_rect.y1 - rect.y1 dy2 = current_rect.y2 - rect.y2 deltas_frame.append((dx1, dx2, dy1, dy2)) current_rect.load_trackID(rect.trackID) current_frame.append_labeled_rect(current_rect) else: break deltas_video.append(deltas_frame) else: trackID = 1 picked_rect = Utils_Tensorbox.NMS(frame_info.rects) for rect in picked_rect: current_rect = rect.duplicate() current_rect.load_trackID(trackID) current_frame.append_labeled_rect(current_rect) trackID = trackID + 1 previous_frame = current_frame.duplicate() previous_frame.rects = multiclass_rectangle.duplicate_rects( current_frame.rects) print("Current Frame obj:%d" % len(current_frame.rects)) tracked_video.insert(len(tracked_video), current_frame) return tracked_video