当前位置: 首页>>代码示例>>Python>>正文


Python Detector.detect_faces方法代码示例

本文整理汇总了Python中detector.Detector.detect_faces方法的典型用法代码示例。如果您正苦于以下问题:Python Detector.detect_faces方法的具体用法?Python Detector.detect_faces怎么用?Python Detector.detect_faces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在detector.Detector的用法示例。


在下文中一共展示了Detector.detect_faces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Cropper

# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import detect_faces [as 别名]
class Cropper(object):
    """Cropper"""
    def __init__(self):
        super(Cropper, self).__init__()
        self.detector  = Detector()

    @staticmethod
    def _bounding_rect(faces):
        top,    left  =  sys.maxint,  sys.maxint
        bottom, right = -sys.maxint, -sys.maxint
        for (x, y, w, h) in faces:
            if x < left:
                left = x
            if x+w > right:
                right = x+w
            if y < top:
                top = y
            if y+h > bottom:
                bottom = y+h
        return top, left, bottom, right

    def crop(self, img, target_width, target_height):
        original_height,  original_width  = img.shape[:2]
        faces = self.detector.detect_faces(img)
        if len(faces) == 0: # no detected faces
            target_center_x = original_width / 2
            target_center_y = original_height / 2
        else:
            top, left, bottom, right  = self._bounding_rect(faces)
            target_center_x = (left + right) / 2
            target_center_y = (top + bottom) / 2
        target_left = target_center_x - target_width / 2
        target_right = target_left + target_width
        target_top = target_center_y - target_height / 2
        target_bottom = target_top + target_height
        if target_top < 0:
            delta = abs(target_top)
            target_top += delta
            target_bottom += delta
            if target_bottom > original_height:
                target_bottom = original_height
        if target_left < 0:
            delta = abs(target_left)
            target_left += delta
            target_right += delta
            if target_right > original_width:
                target_right = original_width
        return img[target_top:target_bottom, target_left:target_right]
开发者ID:sandow-digital,项目名称:easy-thumbnails-cropman,代码行数:50,代码来源:cropper.py


注:本文中的detector.Detector.detect_faces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。