从IP摄像头使用开放式检测面部

2024-05-19 02:28:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用一个IP摄像头通过opencv(python)通过192.168.1.36:8080 url检测人脸。我可以完美地连接到移动摄像头(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 (most recent call last): File "/home/nima-s-h/PycharmProjects/FaceRecoUsingDlib/FaceDetector.py", line 14, in cv2.imshow('frame', frame) cv2.error: OpenCV(4.1.0) /io/opencv/modules/highgui/src/window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'


Tags: inimportipimglinewidthcv2detector

热门问题