0

I am using Python 2.7.11 and opencv 2.4.9. I have two prgram for the video face detecting and people detecting. However, it is smooth for the face detecting but slow or the people detecting.

Face Detecting:

faceCascade = cv2.CascadeClassifier('C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)
while True:
    ret, frame = video_capture.read()

    faces = faceCascade.detectMultiScale(
        frame,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )

    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()

People Detecting:

hog = cv2.HOGDescriptor()
hog.setSVMDetectorcv2.HOGDescriptor_getDefaultPeopleDetector())
video_capture = cv2.VideoCapture(0)
while True:
    ret, frame = video_capture.read()    

    (rects, weights) = hog.detectMultiScale(
        frame, 
        winStride=(4, 4),
        padding=(8, 8), 
        scale=1.05
    )

    rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])

    pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)


    for (xA, yA, xB, yB) in pick:
        cv2.rectangle(frame, (xA, yA), (xB, yB), (0, 255, 0), 2)

    cv2.imshow("Before NMS", frame)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

video_capture.release()
cv2.destroyAllWindows()
VICTOR
  • 1,894
  • 5
  • 25
  • 54

1 Answers1

1

Actually Human detection is a very time consuming algorithm. You check the algorithm in detail here. We can change the arguments passing to hog function. Like winStride, padding and scale it's change the speed of algorithm. Only do the fine tuning else it's effects the result.

Or you can implement an another step before the People detection. Like motion detection,then only check for the people if there is any kind of motions is occur. You can find the python code for motion detection here. So it's remove the unnecessary check for people.

Rahul K P
  • 15,740
  • 4
  • 35
  • 52