Skip to content Skip to sidebar Skip to footer

Hog People Detection Opencv Using Webcam

I am trying to detect people using a webcam. I have already tried detecting people using a video and it worked. When I change it from video to webcam the detection does not work.

Solution 1:

If it works with an ordinary video, I can't see why it wouldn't work with a webcam unless the processed frames vary significantly (i.e. too much noise, too large people etc.).

Are you getting image from the webcam at all (I don't see it in your code)? If it's a USB webcam, it's very likely that everything will work using OpenCV VideoReader functionality. You simply get frames from your webcam one after another in a loop. It's described in details in this tutorial: http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html

Solution 2:

Try this: if your are using Laptop's Internal web Cam then put value 0 in

Frame=cv2.VideoCapture(0)

if you are using External Webcam then put value 1 in

Frame=cv2.VideoCapture(1)

Here is Full code:

from imutils.object_detection import non_max_suppression
from imutils import paths
import numpy as np
import imutils
import cv2

Frame=cv2.VideoCapture(0)

hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

whileTrue:
    ret,image=Frame.read()
    image = imutils.resize(image, width=min(350, image.shape[1]))
    orig = image.copy()


    (rects, weights) = hog.detectMultiScale(image, winStride=(4, 4),padding=(8, 8), scale=1.10)

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


    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(image, (xA, yA), (xB, yB), (0, 255, 0), 2)


    cv2.imshow("Body Detection", image)
    cv2.waitKey(1)

Post a Comment for "Hog People Detection Opencv Using Webcam"