Skip to content

Commit

Permalink
add-grayscale-equalized
Browse files Browse the repository at this point in the history
  • Loading branch information
fbtravi committed Nov 28, 2022
1 parent a3ac472 commit fc4284b
Show file tree
Hide file tree
Showing 6 changed files with 33,425 additions and 1 deletion.
11 changes: 10 additions & 1 deletion remotecv/detectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ def get_min_size_for(self, size):
def get_features(self, image):
img = self.get_np_img(image)

return self.get_faces(img, image.size)

def get_grayscale_equalized_features(self, image):
img = self.get_np_img(image)
img_equalized = cv2.equalizeHist(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))

return self.get_faces(img_equalized, image.size)

def get_faces(self, image, image_size):
faces = self.__class__.cascade.detectMultiScale(
img, 1.2, 4, minSize=self.get_min_size_for(image.size)
image, 1.2, 4, minSize=self.get_min_size_for(image_size)
)
faces_scaled = []

Expand Down
30 changes: 30 additions & 0 deletions remotecv/detectors/face_grayscale_equalized_detector/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2022 globo.com <thumbor@g.globo>

from remotecv.detectors import CascadeLoaderDetector

HAIR_OFFSET = 0.12


class FaceGrayscaleEqualizedDetector(CascadeLoaderDetector):
def __init__(self):
self.load_cascade_file(__file__, "haarcascade_frontalface_default.xml")

def __add_hair_offset(self, top, height):
return max(0, top - height * HAIR_OFFSET)

def detect(self, image):
features = self.get_grayscale_equalized_features(image)
points = []
if features:
for (left, top, width, height), _neighbors in features:
top = self.__add_hair_offset(top, height)
points.append([left, top, width, height])

return points
Loading

0 comments on commit fc4284b

Please sign in to comment.