Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django-OpenCV将弹出式相机窗口集成到静态页面中_Python_Html_Django_Webcam - Fatal编程技术网

Python Django-OpenCV将弹出式相机窗口集成到静态页面中

Python Django-OpenCV将弹出式相机窗口集成到静态页面中,python,html,django,webcam,Python,Html,Django,Webcam,打开和保存网络摄像头图像的OpenCv代码: def webcam(request): camera = cv2.VideoCapture(0) while True: return_value,image = camera.read() cv2.imshow('image',image) if cv2.waitKey(1) & 0xFF == ord('s'): cv2.imwrite('./med

打开和保存网络摄像头图像的OpenCv代码:

def webcam(request):
    camera = cv2.VideoCapture(0)
    while True:
        return_value,image = camera.read()
        cv2.imshow('image',image)
        if cv2.waitKey(1) & 0xFF == ord('s'):
            cv2.imwrite('./media/test.jpg',image)
            break
    camera.release()
    cv2.destroyAllWindows()


    return render(request,'page.html')
这是django项目中的一个函数。当按下Html按钮并打开网络摄像头时,会调用它。但它会在弹出的python窗口中打开它。有人知道我是否可以以及如何将该窗口集成到相同或不同的Html页面中?也就是说,当我按下按钮而不是在网页外打开时,我需要在Html页面本身中打开can


感谢您提前提供的帮助。

实际上,您的计算机会在外部打开一个新的python窗口,因为您在视图中运行它,所以在后端运行。假设您部署了解决方案,它只会尝试打开服务器的摄像头,而不是用户的摄像头

我建议您在前端构建此功能。您可以使用javascript轻松完成此任务:

只需在模板中添加一个
,并将其添加到脚本中:

  function runCam(){
    Webcam.set({
        width: 320,
        height: 240,
        image_format: 'jpeg',
        jpeg_quality: 90
        });
    Webcam.attach('#my_camera');
  }

别忘了在你的身体里添加
onload=“runCam()”
,谢谢,我会试试这个。