我需要在Django的网站上安装一个监控摄像头。我找到了一个关于Youtube的教程,但是很简单。下面是我的代码:
from django.shortcuts import render
from django.views.decorators import gzip
from django.http import StreamingHttpResponse
import cv2
# Create your views here.
@gzip.gzip_page
def Home(request):
try:
cam = videoCamera()
return StreamingHttpResponse(gen(cam), content_type="multipart/x-mixed-replace;boundary=frame")
except:
pass
return render(request, 'index.html')
# Video Capture
class videoCamera(object):
video = cv2.VideoCapture("[user]:[password]@rtsp://[ip-address]:554/sub")
while True:
_, frame = video.read()
cv2.imshow("RTSP", frame)
k = cv2.waitKey(10)
if k == ord('q'):
break
video.release()
cv2.destroyAllWindows()
但是,我遇到一个错误:
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:967: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
有人能帮我吗?
1条答案
按热度按时间ktecyv1j1#
在类中尝试这个摄像机不要忘记导入线程