Esempio n. 1
0
def main(args):
    """
    Processing video, detecting and tracking people on it 
    """

    det = detector_yolo.Detector()

    cap = cv2.VideoCapture(args['input'])
    # cap = cv2.VideoCapture(0)

    if (SAVE_VIDEO):
        video_width = int(cap.get(3))
        video_height = int(cap.get(4))
        video_fps = int(cap.get(5))
        fourcc = cv2.VideoWriter_fourcc(*"MJPG")
        out = cv2.VideoWriter(args['output'], fourcc, video_fps,
                              (video_width, video_height), True)

    frame = 0
    start_time = time.time()

    while (True):
        _, img = cap.read()

        if (img is None):
            break

        if (frame % args['skip_frames'] == 0):
            print("[Tracking]")
            result = detect(img, start_time, det)
        else:
            print("[Predicting]")
            result = track(img)
        # Save frame
        '''if (SAVE_VIDEO):
            out.write(result)'''

        frame += 1

        result = cv2.resize(result, (0, 0), fx=SHOW_SCALE, fy=SHOW_SCALE)
        cv2.putText(result, f'FPS: {frame/(time.time()-start_time)}', (0, 50),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
        cv2.imshow("frame", result)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    if (SAVE_VIDEO):
        out.release()
    cv2.destroyAllWindows()
Esempio n. 2
0
            result = track(img, start_time)
        else:
            # print("Predicting")
            result = predict(img, start_time)

        # Save frame
        if (SAVE_VIDEO):
            out.write(result)

        result = cv2.resize(result, (0, 0), fx=SHOW_SCALE, fy=SHOW_SCALE)

        cv2.imshow("frame", result)
        frame += 1
        # print("Frame:", frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    if (SAVE_VIDEO):
        out.release()
    cv2.destroyAllWindows()


if __name__ == "__main__":
    # det = detector.Detector('models/ssd_resnet50_v1')
    # det = detector.Detector('models/faster_rcnn_resnet101_kitti_2018_01_28', 2)
    det = detector_yolo.Detector()
    # det = detector.Detector()
    main()