Skip to content

Instantly share code, notes, and snippets.

@victormurcia
Created October 20, 2022 21:01
Show Gist options
  • Select an option

  • Save victormurcia/bd53e6448c91920f51dc819ba46be65a to your computer and use it in GitHub Desktop.

Select an option

Save victormurcia/bd53e6448c91920f51dc819ba46be65a to your computer and use it in GitHub Desktop.
detecting players with HOG
#Detecting humans with HOG
path2xml = r'C:\Users\vmurc\Documents\GitHub\opencv\data\haarcascades\haarcascade_fullbody.xml'
fbCascade = cv2.CascadeClassifier(path2xml)
# Initializing the HOG person detector
image = cv2.cvtColor(rgb_img, cv2.COLOR_RGB2GRAY)
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
# Resizing the Image
image = imutils.resize(image, width = min(1000, image.shape[1]))
# Detecting all the regions in the image that has a person inside it
#(regions, _) = hog.detectMultiScale(image, winStride = (2,2), padding = (4, 4), scale = 1.1)
players = fbCascade.detectMultiScale(image, scaleFactor = 1.005, minSize=(20, 20), minNeighbors = 1)
image2 = rgb_img.copy()
# Drawing the regions in the Image
i=0
for (x, y, w, h) in players:
cv2.rectangle(image2, (x, y), (x + w, y + h), (0, 255, 0), 3)
currentbox = image2[y:y+h,x:x+w]
i+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment