Exemplo n.º 1
0
def app(image_path):

    labels = load_labels(cfg.LABEL_PATH)
    
    interpreter = Interpreter(cfg.DETECT_MODEL_PATH)
    interpreter.allocate_tensors()
    _, input_H, input_W, _ = interpreter.get_input_details()[0]['shape']

    for i in range(5):
        image = cv.imread(image_path)
        assert image is not None, 'Invalid image path'

        _start_t = time.time()
        inp_image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
        inp_image = cv.resize(inp_image, (input_W, input_H))
        scores, class_ids, bboxes = detect_objects(interpreter, 
                inp_image, image.shape[:2], thresh=0.6)
        _prx_t = time.time() - _start_t
        LOG.info('FPS: {:.3f}'.format(1/_prx_t))

        image = vis.plotBBoxes(image, bboxes.astype('int'), 
                classes=[labels[idx] for idx in class_ids],
                scores=scores) 
        image = vis.plotInfo(image, 'Raspberry Pi - FPS: {:.2f}'.format(1/_prx_t))
        image = cv.cvtColor(np.asarray(image), cv.COLOR_BGR2RGB)

        cv.imwrite('output.jpg', image)
Exemplo n.º 2
0
 def __drawBoxes(self):
     if len(self.detectedObjects):
         labels = len(self.detectedObjects) * ['strawberry']
         confidence = len(self.detectedObjects) * [0]
         coordinates = [(x, y, x + w, y + h) for x, y, w, h in self.detectedObjects]
         self.frame = vis.plotBBoxes(self.frame, coordinates, labels, confidence)
     self.frame = vis.plotInfo(self.frame, 'Flint View')
     self.frame = cv.cvtColor(np.asarray(self.frame), cv.COLOR_BGR2RGB)
def app(video_link, video_name, show, record, flip_hor, flip_ver):
    # initialize Face Detection net
    face_detector = FaceDetector()

    # initialize Emotioner net
    emotioner = Emotioner()

    # initialize Video Capturer
    cap = cv.VideoCapture(video_link)
    (W, H), FPS = imgproc.cameraCalibrate(cap)
    LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))

    if record:
        time_str = time.strftime(cfg.TIME_FM)
        writer = cv.VideoWriter(video_name+time_str+'.avi',
                cv.VideoWriter_fourcc(*'XVID'), FPS, (W, H))

    while cap.isOpened():
        _, frm = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break

        if flip_ver: frm = cv.flip(frm, 0)
        if flip_hor: frm = cv.flip(frm, 1)

        _start_t = time.time()
        scores, bboxes = face_detector.getFaces(frm, def_score=0.5)
        emos = []
        pbboxes = []
        for i, bbox in enumerate(bboxes):
            x1, y1, x2, y2 = getPadding(frm, bbox)
            face_img = frm[y1:y2, x1:x2]
            emo_idx = emotioner.getEmotion(face_img)
            emos.append(EMOTION[emo_idx])
            pbboxes.append((x1, y1, x2, y2))
        _prx_t = time.time() - _start_t


        if len(bboxes):
            frm = vis.plotBBoxes(frm, pbboxes, emos) 
        frm = vis.plotInfo(frm, 'Raspberry Pi - FPS: {:.3f}'.format(1/_prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if record:
            writer.write(frm)
       
        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break

    if record:
        writer.release()
    cap.release()
    cv.destroyAllWindows()
def app(video_link, video_name, show, flip_hor, flip_ver):
    # initialize Face Detection net
    face_detector = FaceDetector()
    LOG.info('Face Detector initialization done')

    # initialize Face Landmark net
    face_landmarker = FaceLandmarker()
    LOG.info('Face Landmarker initialization done')

    # initialize Video Capturer
    cap = cv.VideoCapture(video_link)
    (W, H), FPS = imgproc.cameraCalibrate(cap, size=720, by_height=True)
    LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))

    while cap.isOpened():
        _, frm = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break

        if flip_ver: frm = cv.flip(frm, 0)
        if flip_hor: frm = cv.flip(frm, 1)

        frm = imgproc.resizeByHeight(frm, 720)

        _start_t = time.time()
        scores, bboxes = face_detector.getFaces(frm, def_score=0.5)

        landmarks = []
        for i, bbox in enumerate(bboxes):
            x1, y1, x2, y2 = bbox
            face_img = frm[y1:y2, x1:x2]
            landmark = face_landmarker.getLandmark(face_img)
            landmark[:, :] += np.array([x1, y1])
            landmarks.append(landmark)
        _prx_t = time.time() - _start_t

        if len(bboxes):
            for i, landmark in enumerate(landmarks):
                for j, point in enumerate(landmark):
                    cv.circle(frm, tuple(point), 3, (0, 255, 0), -1)

            frm = vis.plotBBoxes(frm, bboxes, len(bboxes) * ['face'], scores)

        frm = vis.plotInfo(frm,
                           'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break

    cap.release()
    cv.destroyAllWindows()
def app(video_link, video_name, show=False, record=False):
    # initialize TFLite model
    labels = load_labels(cfg.LABEL_PATH)
    
    interpreter = Interpreter(cfg.DETECT_MODEL_PATH)
    interpreter.allocate_tensors()
    _, input_H, input_W, _ = interpreter.get_input_details()[0]['shape']

    # initialize video capturer
    cap = cv.VideoCapture(video_link)
    (W, H), FPS = imgproc.cameraCalibrate(cap)
    FRM_MOD = int(FPS / cfg.pFPS + 0.5)
    LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))

    if record:
        writer = imgproc.getVideoRecorder(video_name, (W, H), FPS)

    frm_cnt = 0
    while cap.isOpened():
        _, frm = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break

        frm_cnt += 1
        if frm_cnt % FRM_MOD: continue

        _start_t = time.time()
        inp_image = cv.cvtColor(frm, cv.COLOR_BGR2RGB)
        inp_image = cv.resize(inp_image, (input_W, input_H))
        scores, class_ids, bboxes = detect_objects(interpreter, 
                inp_image, frm.shape[:2], thresh=0.6)
        _prx_t = time.time() - _start_t
        LOG.info('FPS: {:.3f}'.format(1/_prx_t))

        frm = vis.plotBBoxes(frm, bboxes.astype('int'), 
                classes=[labels[idx] for idx in class_ids],
                scores=scores) 
        frm = vis.plotInfo(frm, 'Raspberry Pi - FPS: {:.2f}'.format(1/_prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if record:
            writer.write(frm)

        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break

    if record:
        writer.release()
    cap.release()
    cv.destroyAllWindows()
Exemplo n.º 6
0
def app(image_path):
    # initialize Face Detection net
    face_detector = FaceDetector()
    LOG.info('Face Detector initialization done')

    # initialize Face Landmark net
    face_landmarker = FaceLandmarker()
    LOG.info('Face Landmarker initialization done')

    cap = cv.VideoCapture(0)
    while cap.isOpened():
        _, image = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break

        image = imgproc.resizeByHeight(image, 720)

        _start_t = time.time()
        scores, bboxes = face_detector.getFaces(image, def_score=0.5)

        landmarks = []
        for i, bbox in enumerate(bboxes):
            x1, y1, x2, y2 = bbox
            face_img = image[y1:y2, x1:x2]
            landmark = face_landmarker.getLandmark(face_img)

            aligned_img = alignFace(face_img, landmark)
            cv.imshow('aligned-faces' + str(i), aligned_img)

            landmark[:, :] += np.array([x1, y1])
            landmarks.append(landmark)
        _prx_t = time.time() - _start_t

        if len(bboxes):
            for i, landmark in enumerate(landmarks):
                for j, point in enumerate(landmark):
                    cv.circle(image, tuple(point), 3, (0, 255, 0), -1)

            image = vis.plotBBoxes(image, bboxes,
                                   len(bboxes) * ['face'], scores)

        image = vis.plotInfo(image,
                             'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        image = cv.cvtColor(np.asarray(image), cv.COLOR_BGR2RGB)

        cv.imshow(image_path, image)
        key = cv.waitKey(1)
        if key in [27, ord('q')]:
            LOG.info('Interrupted by Users')
            break

    cap.release()
    cv.destroyAllWindows()
Exemplo n.º 7
0
def app(video_link, video_name, show, record, flip_hor, flip_ver):
    # initialize Face Detection net
    object_detector = ObjectDetector()

    # initialize Video Capturer
    cap = cv.VideoCapture(video_link)
    (W, H), FPS = imgproc.cameraCalibrate(cap)
    LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))

    if record:
        time_str = time.strftime(cfg.TIME_FM)
        writer = cv.VideoWriter(video_name + time_str + '.avi',
                                cv.VideoWriter_fourcc(*'XVID'), 20,
                                (1280, 720))

    cnt_frm = 0
    while cap.isOpened():
        _, frm = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break
        cnt_frm += 1

        if flip_ver: frm = cv.flip(frm, 0)
        if flip_hor: frm = cv.flip(frm, 1)
        frm = imgproc.resizeByHeight(frm, 720)

        _start_t = time.time()
        scores, bboxes = object_detector.getObjects(frm, def_score=0.5)
        _prx_t = time.time() - _start_t

        if len(bboxes):
            frm = vis.plotBBoxes(frm, bboxes, len(bboxes) * ['person'], scores)
        frm = vis.plotInfo(frm,
                           'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if record:
            writer.write(frm)

        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break

    if record:
        writer.release()
    cap.release()
    cv.destroyAllWindows()
def app(image_path):
    # initialize Face Detection net
    face_detector = FaceDetector()
    LOG.info('Face Detector initialization done')

    # initialize Face Landmark net
    face_landmarker = FaceLandmarker()
    LOG.info('Face Landmarker initialization done')

    # initialize Face Alignment class
    face_aligner = FaceAligner()
    LOG.info('Face Aligner initialization done')

    # initialize Video Capturer
    image = cv.imread(image_path)
    assert image is not None

    image = imgproc.resizeByHeight(image, 720)

    _start_t = time.time()
    scores, bboxes = face_detector.getFaces(image, def_score=0.5)

    landmarks = []
    for i, bbox in enumerate(bboxes):
        x1, y1, x2, y2 = bbox
        face_img = image[y1:y2, x1:x2]
        landmark = face_landmarker.getLandmark(face_img)

        aligned_img = face_aligner.align(face_img, landmark)
        cv.imshow('aligned-faces' + str(i), aligned_img)

        landmark[:, :] += np.array([x1, y1])
        landmarks.append(landmark)
    _prx_t = time.time() - _start_t

    if len(bboxes):
        for i, landmark in enumerate(landmarks):
            for j, point in enumerate(landmark):
                cv.circle(image, tuple(point), 3, (0, 255, 0), -1)

        image = vis.plotBBoxes(image, bboxes, len(bboxes) * ['face'], scores)

    image = vis.plotInfo(image,
                         'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
    image = cv.cvtColor(np.asarray(image), cv.COLOR_BGR2RGB)

    cv.imshow(image_path, image)
    key = cv.waitKey(0)

    cv.destroyAllWindows()
def app(video_link, video_name, show, flip_hor, flip_ver):
    # initialize Face Detection net
    face_detector = FaceDetector()

    # initialize Video Capturer
    cap = cv.VideoCapture(video_link)
    (W, H), FPS = imgproc.cameraCalibrate(cap)
    LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))

    while cap.isOpened():
        _, frm = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break

        if flip_ver: frm = cv.flip(frm, 0)
        if flip_hor: frm = cv.flip(frm, 1)

        _start_t = time.time()
        scores, bboxes = face_detector.getFaces(frm, def_score=0.5)
        _prx_t = time.time() - _start_t

        if len(bboxes):
            frm = vis.plotBBoxes(frm, bboxes, len(bboxes) * ['face'], scores)
        frm = vis.plotInfo(frm,
                           'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break

    cap.release()
    cv.destroyAllWindows()
Exemplo n.º 10
0
def processFrame(frm, face_detector, face_landmarker):
    _start_t = time.time()
    scores, bboxes = face_detector.getFaces(frm, def_score=0.5)

    landmarks = []
    for i, bbox in enumerate(bboxes):
        x1, y1, x2, y2 = bbox
        face_img = frm[y1:y2, x1:x2]
        landmark = face_landmarker.getLandmark(face_img)
        landmark[:, :] += np.array([x1, y1])
        landmarks.append(landmark)
    _prx_t = time.time() - _start_t

    if len(bboxes):
        for i, landmark in enumerate(landmarks):
            for j, point in enumerate(landmark):
                cv.circle(frm, tuple(point), 3, (0, 255, 0), -1)

        frm = vis.plotBBoxes(frm, bboxes, len(bboxes) * ['face'], scores)

    frm = vis.plotInfo(frm, 'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
    frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

    return frm
Exemplo n.º 11
0
            continue

        start_time = time.time()

    elif (len(bboxes) == 0) and (time.time() - start_time) > delay:
        tracking = 0
        stage = SEARCH_LR
        #go home call
        my_robot.goReady()
        print("go home,cant see anything")
        start_time = time.time()

    if len(bboxes):
        frm = vis.plotBBoxes(frm,
                             [(x, y, x + w, y + h) for x, y, w, h in bboxes],
                             len(bboxes) * ['strawberry'],
                             len(bboxes) * [0])
    frm = vis.plotInfo(frm, 'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
    frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

    # show the frame
    cv.imshow("Frame", frm)
    cv.imwrite("../Frontend/frame.jpg", frm)

    key = cv.waitKey(1)
    if key in [27, ord('q')]:
        break
    #time.sleep(2)

pipeline.stop()
Exemplo n.º 12
0
def app(video_link, video_name, show, record, flip_hor, flip_ver):
    # initialize Face Detection net
    object_detector = ObjectDetector()

    # initialize Video Capturer
    #cap = cv.VideoCapture(video_link)
    cap = WebcamVideoStream(src=cfg.RTSP_URL).start()
    # (W, H), FPS = imgproc.cameraCalibrate(cap.stream)
    # LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))

    if record:
        time_str = time.strftime(cfg.TIME_FM)
        writer = cv.VideoWriter(video_name + time_str + '.avi',
                                cv.VideoWriter_fourcc(*'XVID'), 20,
                                (1280, 720))

    #cnt_frm = 0
    while True:
        frm = cap.read()
        if frm is None:
            continue
        #cnt_frm += 1
        # if(cnt_frm % 5 != 0):
        #     continue
        if flip_ver:
            frm = cv.flip(frm, 0)
        if flip_hor:
            frm = cv.flip(frm, 1)
        frm = imgproc.resizeByHeight(frm, 720)

        _start_t = time.time()
        images, bboxes = object_detector.getObjects(frm, def_score=0.5)
        if images:
            files = []
            for im in images:
                byte_io = BytesIO()
                im.save(byte_io, 'png')
                byte_io.seek(0)
                files.append(('files', byte_io))
            files.append(
                ('bboxes', (None, json.dumps(bboxes), 'application/json')))
            if (len(bboxes)):
                try:
                    requests.post(url=URL, files=files)
                except:
                    continue

        _prx_t = time.time() - _start_t

        if len(bboxes):
            frm = vis.plotBBoxes(frm, bboxes, len(bboxes) * ['person'])
        frm = vis.plotInfo(frm,
                           'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if record:
            writer.write(frm)

        # if show:
        #     cv.imshow(video_name, frm)
        #     key = cv.waitKey(1)
        #     if key in [27, ord('q')]:
        #         LOG.info('Interrupted by Users')
        #         break

    if record:
        writer.release()
Exemplo n.º 13
0
def app(video_link, video_name, show, record, flip_hor, flip_ver):
    # initialize Face Detection net
    config = read_py_config('config.py')
    object_detector = ObjectDetector()
    reid = PersonEmbedder()

    # initialize Video Capturer
    cap = MulticamCapture(video_link)
    #cap = WebcamVideoStream(src=video_link).start()
    # (W, H), FPS = imgproc.cameraCalibrate(cap)
    # LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))
    tracker = MultiCameraTracker(cap.get_num_sources(), reid, **config)
    thread_body = FramesThreadBody(cap, max_queue_length=len(cap.captures) * 2)
    frames_thread = Thread(target=thread_body)
    frames_thread.start()

    if record:
        time_str = time.strftime(cfg.TIME_FM)
        writer = cv.VideoWriter(video_name + time_str + '.avi',
                                cv.VideoWriter_fourcc(*'XVID'), 20,
                                (1280, 720))

    cnt_frm = 0
    counter = 0
    while thread_body.process:
        try:
            frm = thread_body.frames_queue.get_nowait()
        except queue.Empty:
            frm = None
        if frm is None:
            continue
        cnt_frm += 1

        # if flip_ver: frm = cv.flip(frm, 0)
        # if flip_hor: frm = cv.flip(frm, 1)
        _start_t = time.time()
        all_detections = []
        for f in frm:
            f = imgproc.resizeByHeight(f, 640)
            _, bboxes = object_detector.getObjects(f, def_score=0.5)
            all_detections.append(bboxes)

        tracker.process(frm, all_detections, [[]])
        tracked_objects = tracker.get_tracked_objects()
        _prx_t = time.time() - _start_t
        fps = round(1 / _prx_t, 1)
        if len(bboxes):
            frm = visualize_multicam_detections(frm, tracked_objects, fps)
        frm = vis.plotInfo(frm,
                           'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if record:
            writer.write(frm)

        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break
        else:
            if (counter % 10 == 0):
                print(
                    f"IN : {SingleCameraTracker.COUNT_IN}, OUT: {SingleCameraTracker.COUNT_OUT}"
                )
        counter += 1

    thread_body.process = False
    frames_thread.join()
Exemplo n.º 14
0
def app(video_path, video_name, show=False, record=False):
    detector = FaceDetector()
    plugin = detector.getPlugin()
    poser = HeadPoser(plugin=plugin)

    cap = cv.VideoCapture(video_path)
    (W, H), FPS = imgproc.cameraCalibrate(cap)
    _, frm = cap.read()
    frm = imgproc.resizeByHeight(frm)
    H, W = frm.shape[:2]
    FRM_MOD = int(1. * FPS / cfg.pFPS + 0.5)
    LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))

    if record:
        time_str = time.strftime(cfg.TIME_FM)
        writer = cv.VideoWriter(video_name + time_str + '.avi',
                                cv.VideoWriter_fourcc(*'XVID'), FPS, (W, H))

    cnt_frm = 0
    while cap.isOpened():
        _, frm = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break

        cnt_frm += 1
        if cnt_frm % FRM_MOD: continue
        print(cnt_frm)
        frm = imgproc.resizeByHeight(frm)

        _start_t = time.time()
        scores, bboxes = detector.getFaces(frm)

        if len(bboxes):
            for i, bbox in enumerate(bboxes):
                x1, y1, x2, y2 = bbox
                face_image = frm[y1:y2, x1:x2]
                yaw, pitch, roll = poser.estimatePose(face_image)

                cpoint = [(x1 + x2) // 2, (y1 + y2) // 2]
                frm = hvis.draw(frm, cpoint, (yaw, pitch, roll))
        _prx_t = time.time() - _start_t

        frm = vis.plotInfo(frm,
                           'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if record:
            writer.write(frm)

        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break

    if record:
        writer.release()
    cap.release()
    cv.destroyAllWindows()
def app(video_link, video_name, show, record, flip_hor, flip_ver):
    # initialize Face Detection net
    config = read_py_config('config.py')
    object_detector = ObjectDetector()
    reid = PersonEmbedder()

    # initialize Video Capturer
    #cap = MulticamCapture(video_link)
    cap = WebcamVideoStream(src=video_link).start()
    (W, H), FPS = imgproc.cameraCalibrate(cap)
    LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))
    tracker = MultiCameraTracker(1, reid, **config)

    if record:
        time_str = time.strftime(cfg.TIME_FM)
        writer = cv.VideoWriter(video_name + time_str + '.avi',
                                cv.VideoWriter_fourcc(*'XVID'), 20,
                                (1280, 720))

    cnt_frm = 0
    counter = 0
    while True:
        frm = cap.read()
        if frm is None:
            continue
        cnt_frm += 1

        # if flip_ver: frm = cv.flip(frm, 0)
        # if flip_hor: frm = cv.flip(frm, 1)
        _start_t = time.time()
        all_detections = []

        frm = imgproc.resizeByHeight(frm, 640)
        _, bboxes = object_detector.getObjects(frm, def_score=0.5)
        all_detections.append(bboxes)

        tracker.process([frm], all_detections, [[]])
        tracked_objects = tracker.get_tracked_objects()
        _prx_t = time.time() - _start_t
        fps = round(1 / _prx_t, 1)
        if len(bboxes):
            frm = visualize_multicam_detections([frm], tracked_objects, fps)
        frm = vis.plotInfo(frm,
                           'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if record:
            writer.write(frm)

        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break
        else:
            if (counter % 10 == 0):
                print(
                    f"IN : {SingleCameraTracker.COUNT_IN}, OUT: {SingleCameraTracker.COUNT_OUT}"
                )
        counter += 1

    if record:
        writer.release()
    cap.release()
    cv.destroyAllWindows()