def make_video_from_list(out_vid_path, frames_list): if frames_list[0] is not None: img = cv2.imread(frames_list[0], True) print frames_list[0] h, w = img.shape[:2] fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') out = cv2.VideoWriter(out_vid_path,fourcc, 20.0, (w, h), True) print("Start Making File Video:%s " % out_vid_path) print("%d Frames to Compress"%len(frames_list)) progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()]) for i in progress(range(0,len(frames_list))): if utils_image.check_image_with_pil(frames_list[i]): out.write(img) img = cv2.imread(frames_list[i], True) out.release() print("Finished Making File Video:%s " % out_vid_path)
def make_video_from_list(out_vid_path, frames_list): if frames_list[0] is not None: img = cv2.imread(frames_list[0], True) print(frames_list[0]) h, w = img.shape[:2] fourcc = cv2.VideoWriter_fourcc(*'mp4v') out = cv2.VideoWriter(out_vid_path,fourcc, 20.0, (w, h), True) print("Start Making File Video:%s " % out_vid_path) print("%d Frames to Compress"%len(frames_list)) progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()]) for i in progress(range(0,len(frames_list))): if utils_image.check_image_with_pil(frames_list[i]): out.write(img) img = cv2.imread(frames_list[i], True) out.release() print("Finished Making File Video:%s " % out_vid_path)
def make_tracked_video(out_vid_path, labeled_video_frames): if labeled_video_frames[0] is not None: img = cv2.imread(labeled_video_frames[0], True) print "Reading Filename: %s"%labeled_video_frames[0] h, w = img.shape[:2] print "Video Size: width: %d height: %d"%(h, w) fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') out = cv2.VideoWriter(out_vid_path,fourcc, 20.0, (w, h), True) print("Start Making File Video:%s " % out_vid_path) print("%d Frames to Compress"%len(labeled_video_frames)) progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()]) for i in progress(range(0,len(labeled_video_frames))): if utils_image.check_image_with_pil(labeled_video_frames[i]): out.write(img) img = cv2.imread(labeled_video_frames[i], True) out.release() print("Finished Making File Video:%s " % out_vid_path)
def make_tracked_video(out_vid_path, labeled_video_frames): if labeled_video_frames[0] is not None: img = cv2.imread(labeled_video_frames[0], True) print("Reading Filename: %s"%labeled_video_frames[0]) h, w = img.shape[:2] print("Video Size: width: %d height: %d"%(h, w)) fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') out = cv2.VideoWriter(out_vid_path,fourcc, 20.0, (w, h), True) print("Start Making File Video:%s " % out_vid_path) print("%d Frames to Compress"%len(labeled_video_frames)) progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()]) for i in progress(range(0,len(labeled_video_frames))): if utils_image.check_image_with_pil(labeled_video_frames[i]): out.write(img) img = cv2.imread(labeled_video_frames[i], True) out.release() print("Finished Making File Video:%s " % out_vid_path)
def bbox_det_TENSORBOX_multiclass(frames_list, path_video_folder, hypes_file, weights_file, pred_idl): from train import build_forward print("Starting DET Phase") #### START TENSORBOX CODE ### lenght = int(len(frames_list)) video_info = [] ### Opening Hypes file for parameters with open(hypes_file, 'r') as f: H = json.load(f) ### Building Network tf.reset_default_graph() googlenet = googlenet_load.init(H) x_in = tf.placeholder(tf.float32, name='x_in', shape=[H['image_height'], H['image_width'], 3]) if H['use_rezoom']: pred_boxes, pred_logits, pred_confidences, pred_confs_deltas, pred_boxes_deltas = build_forward( H, tf.expand_dims(x_in, 0), googlenet, 'test', reuse=None) grid_area = H['grid_height'] * H['grid_width'] pred_confidences = tf.reshape( tf.nn.softmax( tf.reshape(pred_confs_deltas, [grid_area * H['rnn_len'], H['num_classes']])), [grid_area, H['rnn_len'], H['num_classes']]) pred_logits = tf.reshape( tf.nn.softmax( tf.reshape(pred_logits, [grid_area * H['rnn_len'], H['num_classes']])), [grid_area, H['rnn_len'], H['num_classes']]) if H['reregress']: pred_boxes = pred_boxes + pred_boxes_deltas else: pred_boxes, pred_logits, pred_confidences = build_forward( H, tf.expand_dims(x_in, 0), googlenet, 'test', reuse=None) saver = tf.train.Saver() with tf.Session() as sess: sess.run(tf.initialize_all_variables()) saver.restore( sess, weights_file ) ##### Restore a Session of the Model to get weights and everything working #### Starting Evaluating the images print(("%d Frames to DET" % len(frames_list))) progress = progressbar.ProgressBar(widgets=[ progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage(), ' ', progressbar.ETA() ]) frameNr = 0 skipped = 0 for i in progress(list(range(0, len(frames_list)))): current_frame = frame.Frame_Info() current_frame.frame = frameNr current_frame.filename = frames_list[i] if utils_image.isnotBlack( frames_list[i]) & utils_image.check_image_with_pil( frames_list[i]): img = imread(frames_list[i]) # test(frames_list[i]) feed = {x_in: img} (np_pred_boxes, np_pred_logits, np_pred_confidences) = sess.run( [pred_boxes, pred_logits, pred_confidences], feed_dict=feed) _, rects = get_multiclass_rectangles(H, np_pred_confidences, np_pred_boxes, rnn_len=H['rnn_len']) if len(rects) > 0: # pick = NMS(rects) pick = rects print((len(rects), len(pick))) current_frame.rects = pick frameNr = frameNr + 1 video_info.insert(len(video_info), current_frame) print((len(current_frame.rects))) else: skipped = skipped + 1 else: skipped = skipped + 1 print(("Skipped %d Black Frames" % skipped)) #### END TENSORBOX CODE ### return video_info
def bbox_det_TENSORBOX_multiclass(frames_list,path_video_folder,hypes_file,weights_file,pred_idl): from train import build_forward print("Starting DET Phase") #### START TENSORBOX CODE ### lenght=int(len(frames_list)) video_info = [] ### Opening Hypes file for parameters with open(hypes_file, 'r') as f: H = json.load(f) ### Building Network tf.reset_default_graph() googlenet = googlenet_load.init(H) x_in = tf.placeholder(tf.float32, name='x_in', shape=[H['image_height'], H['image_width'], 3]) if H['use_rezoom']: pred_boxes, pred_logits, pred_confidences, pred_confs_deltas, pred_boxes_deltas = build_forward(H, tf.expand_dims(x_in, 0), googlenet, 'test', reuse=None) grid_area = H['grid_height'] * H['grid_width'] pred_confidences = tf.reshape(tf.nn.softmax(tf.reshape(pred_confs_deltas, [grid_area * H['rnn_len'], H['num_classes']])), [grid_area, H['rnn_len'], H['num_classes']]) pred_logits = tf.reshape(tf.nn.softmax(tf.reshape(pred_logits, [grid_area * H['rnn_len'], H['num_classes']])), [grid_area, H['rnn_len'], H['num_classes']]) if H['reregress']: pred_boxes = pred_boxes + pred_boxes_deltas else: pred_boxes, pred_logits, pred_confidences = build_forward(H, tf.expand_dims(x_in, 0), googlenet, 'test', reuse=None) saver = tf.train.Saver() with tf.Session() as sess: sess.run(tf.initialize_all_variables()) saver.restore(sess, weights_file )##### Restore a Session of the Model to get weights and everything working #### Starting Evaluating the images print("%d Frames to DET"%len(frames_list)) progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()]) frameNr=0 skipped=0 for i in progress(range(0, len(frames_list))): current_frame = frame.Frame_Info() current_frame.frame=frameNr current_frame.filename=frames_list[i] if utils_image.isnotBlack(frames_list[i]) & utils_image.check_image_with_pil(frames_list[i]): img = imread(frames_list[i]) # test(frames_list[i]) feed = {x_in: img} (np_pred_boxes,np_pred_logits, np_pred_confidences) = sess.run([pred_boxes,pred_logits, pred_confidences], feed_dict=feed) _,rects = get_multiclass_rectangles(H, np_pred_confidences, np_pred_boxes, rnn_len=H['rnn_len']) if len(rects)>0: # pick = NMS(rects) pick = rects print len(rects),len(pick) current_frame.rects=pick frameNr=frameNr+1 video_info.insert(len(video_info), current_frame) print len(current_frame.rects) else: skipped=skipped+1 else: skipped=skipped+1 print("Skipped %d Black Frames"%skipped) #### END TENSORBOX CODE ### return video_info