connect@howdiyworld.com
|

People Detection

BLOCK DIAGRAM

Procedure

  1. USB Camera
  2. Connections
  3. Program
  4. Output

Procedure

USB Camera

How USB Camera Works: A USB webcam is a camera that connects to a computer, usually through plugging it in to a USB port on the machine. The video is fed to the computer where a software application lets you view the pictures and also transfer them to the Internet.

Connections

  • Connect USB Camera to Raspberry Pi USB.

Python program

#"Leaderpods"

import numpy as np

import cv2

import imutils

from imutils.object_detection import non_max_suppression

#above include library for this people Detection

cap = cv2.VideoCapture(0)# read cam

hog = cv2.HOGDescriptor()

hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

record = False

if record:

fps = 15

capSize = (450,456) # this is the size of my source video

fourcc = cv2.cv.CV_FOURCC(‘m’, ‘p’, ‘4’, ‘v’) # note the lower case

vout = cv2.VideoWriter()

success = vout.open(‘output.mov’,fourcc,fps,capSize,True)

while(True):

ret, image = cap.read()   #read a input from camera

image = imutils.resize(image, width=min(400, image.shape[1]))

orig = image.copy()

(rects, weights) = hog.detectMultiScale(image, winStride=(4, 4),

padding=(8, 8), scale=1.05)

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(‘frame’,image)

if record:

vout.write(image)

if cv2.waitKey(1) & 0xFF == ord(‘q’):

break

cap.release()

if record:

vout.release()

vout = None

cv2.destroyAllWindows()

Output

If people walk in the camera’s view it will detect the person and also say if its a person or not.

Social media & sharing icons powered by UltimatelySocial
Facebook
Twitter
YouTube
LinkedIn
Instagram