I am making a project in Django. And I want to show live feed from camera on a webpage. But I am not sure on how to return live feed I get from a cam on a web page.
Here's my code that I have tried so far but haven't seen any progress.
from django.shortcuts import render
from .forms import FaceAdditionForm
import cv2
import numpy as np
from django.http import StreamingHttpResponse
def capture_video_from_cam():
cap = cv2.VideoCapture(0)
currentFrame = 0
while True:
ret, frame = cap.read()
# Handles the mirroring of the current frame
frame = cv2.flip(frame,1)
currentFrame += 1
def addfaces(request):
add_faces_form = FaceAdditionForm()
if add_faces_form.is_valid():
add_faces_form.save()
return render(request, 'base.html', {'add_faces': add_faces_form})
def show_video_on_page(request):
resp = StreamingHttpResponse(capture_video_from_cam())
return render(request, 'base.html', {'video': resp})
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…