Created
October 20, 2022 21:01
-
-
Save victormurcia/bd53e6448c91920f51dc819ba46be65a to your computer and use it in GitHub Desktop.
detecting players with HOG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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