Created
February 29, 2020 08:11
-
-
Save bitterbit/616b4fbdc5443fb910876646b88d499e to your computer and use it in GitHub Desktop.
Human detector test
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
| import cv2 | |
| import os | |
| import os.path | |
| def main(): | |
| hog = HOG() | |
| haar = HAAR() | |
| folder = "../images/full/" | |
| for p in os.listdir(folder): | |
| path = os.path.join(folder, p) | |
| print ("HOG:", hog.is_human(path), "HAAR:", haar.is_human(path), "path:", p) | |
| class HAAR: | |
| def __init__(self): | |
| path = "/usr/local/share/opencv4/haarcascades/" | |
| self.cascade = cv2.CascadeClassifier(path + 'haarcascade_fullbody.xml') | |
| def is_human(self, path): | |
| img = cv2.imread(path) | |
| gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
| bodies = self.cascade.detectMultiScale(gray, 1.3, 5) | |
| print ("haar", len(bodies)) | |
| for b in bodies: | |
| print(b) | |
| return False | |
| class HOG: | |
| def __init__(self): | |
| # initialize the HOG descriptor/person detector | |
| self.hog = cv2.HOGDescriptor() | |
| self.hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) | |
| def is_human(self, path): | |
| image = cv2.imread(path) | |
| (rects, weights) = self.hog.detectMultiScale(image, winStride=(4, 4), | |
| padding=(8, 8), scale=1.05) | |
| for w in weights: | |
| if w > 1: | |
| return True | |
| return False | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment