Python 无法将捕获的图像保存在正确的目录中

Python 无法将捕获的图像保存在正确的目录中,python,django,opencv,Python,Django,Opencv,我正在从事一个与图像处理相关的项目。我想从网络摄像头中捕获图像,并将其显示在网页上。我正在使用django框架处理web内容 从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.htm

我正在从事一个与图像处理相关的项目。我想从网络摄像头中捕获图像,并将其显示在网页上。我正在使用django框架处理web内容

从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/

中使用当前目录的完整路径或相对路径,在文件路径的第一个“/”之前使用点(“.”)

file = "./detect/static/test_image.png"