Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to detect the body with cv2

import numpy as np
import cv2


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh


def draw_detections(img, rects, thickness = 1):
    for x, y, w, h in rects:
     
        pad_w, pad_h = int(0.15*w), int(0.05*h)
        cv2.rectangle(img, (x+pad_w, y+pad_h), (x+w-pad_w, y+h-pad_h), (0, 255, 0), thickness)


if __name__ == '__main__':

    hog = cv2.HOGDescriptor()
    hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )
    cap=cv2.VideoCapture('vid.avi')
    while True:
        _,frame=cap.read()
        found,w=hog.detectMultiScale(frame, winStride=(8,8), padding=(32,32), scale=1.05)
        draw_detections(frame,found)
        cv2.imshow('feed',frame)
        ch = 0xFF & cv2.waitKey(1)
        if ch == 27:
            break
    cv2.destroyAllWindows()
Comment

PREVIOUS NEXT
Code Example
Python :: python move all txt files 
Python :: python three periods 
Python :: python hewwo world 
Python :: socket python how to check if server alive 
Python :: sns countplot show only largest 
Python :: Define a python function day_of_week, which displays the day name for a given date supplied in the form (day,month,year). 
Python :: COLLECTING 
Python :: pprint dic without sorting 
Python :: total keywords in python 
Python :: pandas dexcribe only one column 
Python :: modbusfc03 python 
Python :: como usar o Self no python 
Python :: importing modules 
Python :: quicksort python 
Python :: nested list comprehensions 
Python :: pandas merge validate 
Python :: python 1.0 
Python :: how to add colors in python 
Python :: pandas add time to datetime 
Python :: append multiple elements python 
Python :: python interpreter 
Python :: remove a columns in pandas 
Python :: flask socketio send 
Python :: how to add virtual environment in vscode 
Python :: python len 
Python :: python bot 
Python :: import libraries to Jupyter notebook 
Python :: Count upper case characters in a string 
Python :: del en python 
Python :: new line 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =