Created
June 22, 2022 04:06
-
-
Save haipnh/e45ca590bc4394adf4b443c512c65f7a to your computer and use it in GitHub Desktop.
This is an example how to play video on Jupyter using OpenCV and IPythone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from IPython.display import display, Image | |
import time | |
video_path = "./HowDeepIsYourLove.mp4" | |
video = cv2.VideoCapture(video_path) | |
display_handle=display(None, display_id=True) | |
kernel = np.ones((5,5),np.float32)/25 | |
try: | |
while True: | |
start = time.time() | |
_, frame = video.read() | |
# frame = cv2.flip(frame, 1) # if your camera reverses your image | |
frame = cv2.filter2D(frame,-1,kernel) | |
_, frame = cv2.imencode('.jpeg', frame) | |
end = time.time() | |
fps = 1/(end-start) | |
display_handle.update(Image(data=frame.tobytes())) | |
except KeyboardInterrupt: | |
pass | |
finally: | |
video.release() | |
display_handle.update(None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment