-2
我正在研究与图像处理相关的项目。我想从网络摄像头捕捉图像,并希望将其显示在网页上。我正在使用django框架的网络东西。无法将拍摄图像保存在正确的目录中
程序从网络摄像头捕捉到的图像中views.py:
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
import cv2
def home(request):
return render(request,'detect/home.html',{})
def get_image(camera):
retval, im = camera.read()
return im
def webcam():
camera_port = 0
ramp_frames = 30
camera = cv2.VideoCapture(camera_port)
for i in xrange(ramp_frames):
temp = get_image(camera)
print("Taking image...")
camera_capture = get_image(camera)
file = "/detect/static/test_image.png"
cv2.imwrite(file, camera_capture)
del(camera)
@csrf_exempt
def display(request):
webcam()
return render(request,'detect/display.html',{})
如果我不提任何路径,只包括名称的图像文件(file =“test_image.png”),图像被保存在/ moody/project中。 我想将图像保存在/ moody/project/detect/static /中。