Last active
October 21, 2019 13:49
-
-
Save jagin/263ef78d1c7ebfe06bc7988818cc3ec0 to your computer and use it in GitHub Desktop.
Face detection using Haar Cascade (see https://medium.com/deepvisionguru/modular-image-processing-pipeline-using-opencv-and-python-generators-9edca3ccb696)
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 | |
from pipeline.pipeline import Pipeline | |
class CascadeDetectFaces(Pipeline): | |
def __init__(self, classifier): | |
# load the face detector | |
self.detector = cv2.CascadeClassifier(classifier) | |
super(DetectFaces, self).__init__() | |
def map(self, data): | |
image = data["image"] | |
# Detect faces | |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
face_rects = self.detector.detectMultiScale(gray, scaleFactor=1.05, minNeighbors=5, | |
minSize=(30, 30), flags=cv2.CASCADE_SCALE_IMAGE) | |
data["face_rects"] = face_rects | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment