-1

I am trying to use an IP camera to detect faces by opencv(python) by 192.168.1.36:8080 url. I can connect to a mobile camera (Ip camera) perfectly but openCV cannot detect faces. When I use laptop camera everything fine but by Ip camera, I cannot detect faces. It's my code:

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()

I get this error:

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'

Nima.S-H
  • 777
  • 1
  • 9
  • 19
  • What do you mean by "I cannot detect faces" ? dets is always empty or you get an error ? – emlot77 Jun 20 '19 at 08:08
  • @emlot77 I forgot to say my error, look again please – Nima.S-H Jun 20 '19 at 08:17
  • It seems that the `cv2.VideoCapture` has not been initialized correctly due to an invalid URL, thus returning an empty frame. The `img` variable should be `None` and `ret_val` should be `False` in this case. Replace `while True:` with `while cam.isOpened():` and see if the error is still there. – sgarizvi Jun 20 '19 at 09:10
  • I solve this problem by rtsp://192.168.1.4:8080/h264_ulaw.sdp url. but I opencv cannot detect face – Nima.S-H Jun 20 '19 at 09:14
  • Now the video stream is good but you have empty dets? Did you check that the input image in the function detector(img) is correct ? – emlot77 Jun 20 '19 at 09:22
  • check in your loop if your cam isOpened...and display the image. your error says that there is no image to be displayed in imshow – Y.AL Jun 20 '19 at 10:33
  • Dear @emlot77 video stream is fine but opencv could not find face, It dosent work – Nima.S-H Jun 20 '19 at 13:43
  • @Y.AL yes, you right. It return false – Nima.S-H Jun 20 '19 at 14:00

1 Answers1

0

Try this address:

http://192.168.1.40:8080/abc.mjpg

instead of

http://192.168.1.40:8080
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56