def extract_tracked_frames(): gpu_id = 1 ctx = mx.gpu(gpu_id) video_path = '../../dataset/OptFace/CompressedVideo' detector = Detector('../../model/faster_rcnn/mxnet-face-fr50', ctx) img_id_map = {} img_cnt = 0 cls_cnt = 0 for video_file in os.listdir(video_path): frames_dir = os.path.join('../../dataset/OptFace/tracked_frames', video_file) if not os.path.exists(frames_dir): os.mkdir(frames_dir) print('processing video: %s' % video_file) video_dir = os.path.join(video_path, video_file) video_capture = cv2.VideoCapture(video_dir) fps = video_capture.get(cv2.CAP_PROP_FPS) size = (int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH)), \ int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT))) num_frame = 0 tracker = sort.Sort() while video_capture.grab(): flag, frame = video_capture.retrieve() det = detector.detect_face(frame) ids = tracker.update(det) # if ids.shape[0] > 0: # print(ids) sticked_img, crops = Function.stick_boxes(frame, ids) for i in range(ids.shape[0]): cur_id = int(ids[i][4]) if img_id_map.get(cur_id) is None: img_id_map[cur_id] = cls_cnt cls_cnt += 1 dump_crop(frames_dir, crops[i], img_id_map[cur_id], img_cnt) img_cnt += 1 """
recognizer.load_train_data(train_data, label, reverse_cls_map) img_id_map = {} img_cnt = 0 cls_cnt = 0 video_list = [l.strip() for l in open(video_list)] for video_file in video_list[0:1]: print('processing video: %s' % video_file) video_dir = os.path.join(video_path, video_file) video_capture = cv2.VideoCapture(video_dir) fps = video_capture.get(cv2.CAP_PROP_FPS) size = (int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH)), \ int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT))) num_frame = 0 tracker = sort.Sort() while video_capture.grab(): flag, frame = video_capture.retrieve() det = detector.detect_face(frame) ids = tracker.update(det) sticked_img, crops = Function.stick_boxes(frame, ids) for crop in crops: crop_name = recognizer.predict(crop) print('crop name: %s' % (crop_name)) # sys.exit() cv2.imshow('a', sticked_img) if cv2.waitKey(5) == ord('q'): break