【发布时间】:2019-11-02 23:03:19
【问题描述】:
我正在尝试使用 IP 摄像头通过 192.168.1.36:8080 url 通过 opencv(python) 检测人脸。我可以完美地连接到移动摄像头(IP 摄像头),但 openCV 无法检测到人脸。 当我使用笔记本电脑摄像头时,一切都很好,但通过 IP 摄像头,我无法检测到人脸。 这是我的代码:
import dlib
import cv2
detector = dlib.get_frontal_face_detector()
cam = cv2.VideoCapture("http://192.168.1.40:8080")
color_green = (0,255,0)
line_width = 3
while True:
ret_val, img = cam.read()
# rgb_image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
dets = detector(img)
for det in dets:
cv2.rectangle(img,(det.left(), det.top()), (det.right(), det.bottom()), color_green, line_width)
cv2.imshow('my webcam', img)
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()
我收到此错误:
Traceback(最近一次调用最后一次):文件 "/home/nima-s-h/PycharmProjects/FaceRecoUsingDlib/FaceDetector.py", 第 14 行,在 cv2.imshow('frame', frame) cv2.error: OpenCV(4.1.0) /io/opencv/modules/highgui/src/window.cpp:352: error: (-215:Assertion 失败)size.width>0 && size.height>0 in function 'imshow'
【问题讨论】:
-
“我无法检测到人脸”是什么意思? dets 总是为空或者你得到一个错误?
-
@emlot77 我忘了说我的错误,请再看一遍
-
似乎
cv2.VideoCapture由于无效的URL没有正确初始化,因此返回一个空帧。在这种情况下,img变量应该是None和ret_val应该是False。将while True:替换为while cam.isOpened():,看看错误是否仍然存在。 -
我通过 rtsp://192.168.1.4:8080/h264_ulaw.sdp url 解决了这个问题。但我的opencv无法检测到人脸
-
现在视频流很好但是你有空dets?你检查函数检测器(img)中的输入图像是否正确?