Friday, September 30
Shadow

OpenCV Player

import logging

import cv2

def main():
    cap = cv2.VideoCapture("uhU.webm")

    cap.set(cv2.CAP_PROP_POS_MSEC, 1000.0)
    #cap.set(cv2.CAP_PROP_POS_FRAMES, 1000.0)
    w, h = cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
    fps = cap.get(cv2.CAP_PROP_FPS)

    stop = False
    while not stop:
        # Read frame
        ret, frame = cap.read()
        if ret == False:
            raise RuntimeError("Failed to read frame")
        frame_i = cap.get(cv2.CAP_PROP_POS_FRAMES)

        # Resize
        #breakpoint()
        frame = cv2.resize(frame, tuple(int(d*0.33) for d in frame.shape[1:None:-1]))

        # Display
        cv2.imshow("Frame", frame)
        if cv2.waitKey(25) == ord("q"):
            stop = True
            break

        if not cap.isOpened() or stop:
            break

    cap.release()
    cv2.destroyAllWindows()


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)

    main()

Leave a Reply