def recognition(frame): cascade = face_cascade() frame = filter.grayscale(frame) minSize = (cfg.get_options('size'), cfg.get_options('size')) faces = cascade.detectMultiScale( frame, scaleFactor=cfg.get_options('scaleFactor'), minNeighbors=cfg.get_options('minNeighbors'), minSize=minSize, flags=cv2.CASCADE_SCALE_IMAGE) return frame, faces
def image(gray, width, height): return cv2.resize(gray, (width, height), interpolation=cfg.get_options('interpolation'))
def scale(frame): alt = int(frame.shape[0] / frame.shape[1] * cfg.get_options('resize')) return image(frame, cfg.get_options('resize'), alt)
def compare(gray, rect): factor = cfg.get_options('size') (x, y, w, h) = rect gray = image(gray[y:y + h, x:x + w], factor, factor) return gray
def text(frame, text, rect): (x, y, w, h) = rect cv2.rectangle(frame, (x - 1, y - 25), (x + 2 + w, y), cfg.get_options('color'), cv2.FILLED) cv2.putText(frame, text, (x + 6, y - 6), cv2.FONT_HERSHEY_DUPLEX, 0.5, (0, 0, 0), cfg.get_options('filled'))
def rectangle(frame, rect): color = cfg.get_options('color') (x, y, w, h) = rect cv2.rectangle(frame, (x, y), (x + w, y + h), color, cfg.get_options('filled'))
def face_cascade(): return cv2.CascadeClassifier(cfg.get_options('classificator'))