我正在Django做一个项目。并在网页上通过摄像头进行了现场直播。我还在处理视频,以检测人脸和手势。但我无法将数组(即包含视频功能的数组,如是否检测到人脸、手势等)发送到模板
视图。py:
from django.shortcuts import render
from django.http.response import StreamingHttpResponse
from streamapp.camera import VideoCamera
from django.http import HttpResponse
def gen(camera):
while True:
frame = camera.get_frame()
feature = camera.render_features()
print(feature)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
def video_feed(request):
return StreamingHttpResponse(gen(VideoCamera()),
content_type='multipart/x-mixed-replace; boundary=frame')
def index(request):
return render(request, 'streamapp/home.html')
url.py:
from django.urls import path, include
from streamapp import views
urlpatterns = [
path('', views.index, name='index'),
path('video_feed/', views.video_feed, name='video_feed'),
]
在View.py第10行中,功能是我希望在网页(home.html)中访问的数组。 如何将该数组传递给模板
在传递帧之前,将帧返回到字节,
frame.tobytes()
在HTML文件中,添加以下代码以从views.py请求streaminghttpresponse
相关问题 更多 >
编程相关推荐