Skip to content

Instantly share code, notes, and snippets.

@aniketmaithani
Last active April 26, 2021 04:03
Show Gist options
  • Save aniketmaithani/7fd41f862dc69a72f11de6029ce217bc to your computer and use it in GitHub Desktop.
Save aniketmaithani/7fd41f862dc69a72f11de6029ce217bc to your computer and use it in GitHub Desktop.
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self):
ret, image = self.video.read()
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
def gen(camera):
while True:
frame = camera.get_frame()
yield(b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@gzip.gzip_page
def livefe(request):
try:
return StreamingHttpResponse(gen(VideoCamera()), content_type="multipart/x-mixed-replace;boundary=frame")
except:
pass
# Except Pass is BAD HABIT :P
@Crazz-Zaac
Copy link

I have a situation where I need to stream multiple cameras running in thread at a time. I am supposed to display frames from these cameras on a template with each camera having different card like layout. I've done something very similar to yours but this takes up the entire page. How can I display only on a respective card for frames coming from respective cameras??

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