Skip to content

Instantly share code, notes, and snippets.

@haipnh
Created June 22, 2022 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haipnh/e45ca590bc4394adf4b443c512c65f7a to your computer and use it in GitHub Desktop.
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
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