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


Python point.FocalPoint类代码示例

本文整理汇总了Python中thumbor.point.FocalPoint的典型用法代码示例。如果您正苦于以下问题:Python FocalPoint类的具体用法?Python FocalPoint怎么用?Python FocalPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: should_append_the_returned_focal_points_to_context_request

            def should_append_the_returned_focal_points_to_context_request(self, topic):
                focal_point1_repr = FocalPoint.from_square(1, 2, 3, 4).to_dict()
                focal_point2_repr = FocalPoint.from_square(5, 6, 7, 8).to_dict()

                calls = topic.context.request.focal_points.append.call_args_list

                first_call_arg_repr = calls[0][0][0].to_dict()
                secon_call_arg_repr = calls[1][0][0].to_dict()

                expect(first_call_arg_repr).to_equal(focal_point1_repr)
                expect(secon_call_arg_repr).to_equal(focal_point2_repr)
开发者ID:APSL,项目名称:thumbor,代码行数:11,代码来源:cascade_loader_detector_vows.py

示例2: after_smart_detect

    def after_smart_detect(self, focal_points=[], points_from_storage=False):
        self.manual_crop()
        self.calculate_target_dimensions()

        for point in focal_points:
            self.context.request.focal_points.append(FocalPoint.from_dict(point))

        if self.context.request.focal_points and self.context.modules.storage and not points_from_storage:
            storage = self.context.modules.storage
            points = []
            for point in self.context.request.focal_points:
                points.append(point.to_dict())

            storage.put_detector_data(self.smart_storage_key, points)

        self.adjust_focal_points()

        if self.context.request.debug:
            self.debug()
        else:
            if self.context.request.fit_in:
                self.fit_in_resize()
            else:
                self.auto_crop()
                self.resize()
            self.flip()

        self.done_callback()
开发者ID:MechanisM,项目名称:thumbor,代码行数:28,代码来源:transformer.py

示例3: smart_detect

    def smart_detect(self):
        if self.context['detectors'] and self.context['smart']:
            storage = self.context['storage']
            engine = self.context['engine']
            storage_key = '%s_%d_%d' % (self.context['image_url'], engine.size[0], engine.size[1])
            if self.context['crop_left']:
                storage_key = storage_key + '_%d_%d_%d_%d' % (self.context['crop_left'],
                                                              self.context['crop_top'],
                                                              self.context['crop_right'],
                                                              self.context['crop_bottom']
                                                             )
            focal_points = storage.get_detector_data(storage_key)
            if focal_points:
                for point in focal_points:
                    self.context['focal_points'].append(FocalPoint.from_dict(point))
            else:
                detectors = self.context['detectors']
                detectors[0](index=0, detectors=detectors).detect(self.context)

                points = []
                focal_points = self.context['focal_points']

                for point in focal_points:
                    points.append(point.to_dict())

                storage.put_detector_data(storage_key, points)
开发者ID:cezarsa,项目名称:thumbor,代码行数:26,代码来源:transformer.py

示例4: features_to_focal_points

 def features_to_focal_points(cls, features):
     focal_points = []
     for (left, top, width, height), neighbors in features:
         top = cls.add_hair_offset(top, height)
         focal_points.append(
             FocalPoint.from_square(left, top, width, height, origin="Face Detection"))
     return focal_points
开发者ID:RealGeeks,项目名称:thumbor,代码行数:7,代码来源:distributed_collage.py

示例5: adjust_focal_points

    def adjust_focal_points(self):
        source_width, source_height = self.engine.size

        self.focal_points = None

        if self.context.request.focal_points:
            if self.context.request.should_crop:
                self.focal_points = []
                crop = self.context.request.crop
                for point in self.context.request.focal_points:
                    if point.x < crop['left'] or point.x > crop['right'] or point.y < crop['top'] or point.y > crop['bottom']:
                        continue
                    point.x -= crop['left'] or 0
                    point.y -= crop['top'] or 0
                    self.focal_points.append(point)
            else:
                self.focal_points = self.context.request.focal_points

        if not self.focal_points:
            self.focal_points = [
                FocalPoint.from_alignment(self.context.request.halign,
                                          self.context.request.valign,
                                          source_width,
                                          source_height)
            ]

        self.engine.focus(self.focal_points)
开发者ID:caeugusmao,项目名称:thumbor,代码行数:27,代码来源:transformer.py

示例6: detect

    def detect(self, context):
        features = self.get_features(context)

        if features:
            for (left, top, width, height), neighbors in features:
                context['focal_points'].append(FocalPoint.from_square(left, top, width, height))
        else:
            self.next(context)
开发者ID:douglas,项目名称:thumbor,代码行数:8,代码来源:__init__.py

示例7: detect

    def detect(self, callback):
        features = self.get_features()

        if features:
            for square, neighbors in features:
                self.context.request.focal_points.append(FocalPoint.from_square(*square))
            callback()
        else:
            self.next(callback)
开发者ID:5um1th,项目名称:thumbor,代码行数:9,代码来源:local_detector.py

示例8: calculate_focal_points

 def calculate_focal_points(self):
     if self.context['focal_points']:
         self.focal_points = self.context['focal_points']
     else:
         self.focal_points = [
             FocalPoint.from_alignment(self.context['halign'],
                                       self.context['valign'],
                                       self.source_width,
                                       self.source_height)
         ]
开发者ID:rootart,项目名称:thumbor,代码行数:10,代码来源:transformer.py

示例9: detect

    def detect(self, callback):
        features = self.get_features()

        if features:
            for (left, top, width, height), neighbors in features:
                top = self.__add_hair_offset(top, height)
                self.context.request.focal_points.append(
                    FocalPoint.from_square(left, top, width, height, origin="Face Detection")
                )
            callback()
        else:
            self.next(callback)
开发者ID:APSL,项目名称:thumbor,代码行数:12,代码来源:__init__.py

示例10: extract_focal

    def extract_focal(self):
        parts = self.parse_url(self.context.request.image_url)
        if parts:
            image, top, right, left, bottom = parts
            top, right, left, bottom = int(top), int(right), int(left), int(bottom)

            width = right - left
            height = bottom - top
            self.context.request.focal_points.append(
                FocalPoint.from_square(left, top, width, height, origin="Original Extraction")
            )
            self.context.request.image_url = image
开发者ID:RealGeeks,项目名称:thumbor,代码行数:12,代码来源:extract_focal.py

示例11: focal

    def focal(self, focal_string):
        parsed = self.focal_regex.match(focal_string)

        if parsed:
            left, top, right, bottom = parsed.groups()
            left, top, right, bottom = int(left), int(top), int(right), int(bottom)
            width = right - left
            height = bottom - top

            if width and height:
                self.context.request.focal_points.append(
                    FocalPoint.from_square(left, top, width, height, origin="Explicit")
                )
开发者ID:5um1th,项目名称:thumbor,代码行数:13,代码来源:focal.py

示例12: calculate_focal_points

    def calculate_focal_points(self):
        source_width, source_height = self.engine.size

        if self.context['focal_points']:
            self.focal_points = self.context['focal_points']
        else:
            self.focal_points = [
                FocalPoint.from_alignment(self.context['halign'],
                                          self.context['valign'],
                                          source_width,
                                          source_height)
            ]

        self.engine.focus(self.focal_points)
开发者ID:cezarsa,项目名称:thumbor,代码行数:14,代码来源:transformer.py

示例13: calculate_focal_points

    def calculate_focal_points(self):
        source_width, source_height = self.engine.size

        if self.context.request.focal_points:
            self.focal_points = self.context.request.focal_points
        else:
            self.focal_points = [
                FocalPoint.from_alignment(self.context.request.halign,
                                          self.context.request.valign,
                                          source_width,
                                          source_height)
            ]

        self.engine.focus(self.focal_points)
开发者ID:mikelikespie,项目名称:thumbor,代码行数:14,代码来源:transformer.py

示例14: process

 def process(self, canvas_width, canvas_height, size):
     try:
         self.engine.load(self.buffer, self.extension)
         width, height = self.engine.size
         new_width, new_height = calc_new_size_by_height(width, height, canvas_height)
         focal_points = StandaloneFaceDetector.features_to_focal_points(
             StandaloneFaceDetector.get_features(self.thumbor_filter.context, self.engine))
         if focal_points:
             self.resize_focal_points(focal_points, float(new_width) / width)
         else:
             focal_points.append(FocalPoint.from_alignment('center', 'top', new_width, new_height))
         self.engine.resize(new_width, new_height)
         self.engine.focus(focal_points)
         StandaloneFaceDetector.auto_crop(self.engine, focal_points, size, canvas_height)
     except Exception as err:
         logger.exception(err)
开发者ID:gi11es,项目名称:thumbor-debian,代码行数:16,代码来源:distributed_collage.py

示例15: detect

    def detect(self, callback):
        try:
            features = self.get_features()
        except Exception:
            logger.warn('Error during face detection; skipping to next detector')
            self.next(callback)
            return

        if features:
            for (left, top, width, height), neighbors in features:
                top = self.__add_hair_offset(top, height)
                self.context.request.focal_points.append(
                    FocalPoint.from_square(left, top, width, height, origin="Face Detection")
                )
            callback()
        else:
            self.next(callback)
开发者ID:gi11es,项目名称:thumbor-debian,代码行数:17,代码来源:__init__.py


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