Skip to content

Instantly share code, notes, and snippets.

@jagin
Last active October 21, 2019 13:49
Show Gist options
  • Save jagin/263ef78d1c7ebfe06bc7988818cc3ec0 to your computer and use it in GitHub Desktop.
Save jagin/263ef78d1c7ebfe06bc7988818cc3ec0 to your computer and use it in GitHub Desktop.
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