Skip to content

Instantly share code, notes, and snippets.

@addisaden
Last active November 25, 2019 02:54
Show Gist options
  • Save addisaden/b5d44b5c06172733d9edda4bcf9326b2 to your computer and use it in GitHub Desktop.
Save addisaden/b5d44b5c06172733d9edda4bcf9326b2 to your computer and use it in GitHub Desktop.
get an unbreakable (well everything is breakable) streaminput in opencv python. this could be a replacement for the rtsp streaming which are really fragile if used in VideoCapture
#!/bin/env python3
#-*- encoding: utf-8 -*-
import cv2
import numpy as np
# start this:
# ffmpeg -i /dev/video0 -f mpegts udp://localhost:1337
# ffmpeg -i rtsp://... -f mpegts udp://localhost:1337
cameraCapture = cv2.VideoCapture('udp://localhost:1337')
cv2.namedWindow('MyWindow')
print('Showing camera feed. Click window or press any key to stop.')
while True:
success, frame = cameraCapture.read()
cv2.imshow('MyWindow', frame)
if cv2.waitKey(1) & 0xff == ord("q"):
break
cv2.destroyWindow('MyWindow')
cameraCapture.release()
@iagorichard
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment