• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python point.FocalPoint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: detect

    def detect(self, context):
        size = context['engine'].size
        image_header = cv.CreateImageHeader(size, cv.IPL_DEPTH_8U, 3)
        cv.SetData(image_header, Image.open(StringIO(context['buffer'])).tostring())
        
        grayscale = cv.CreateImage(size, 8, 1)
        cv.CvtColor(image_header, grayscale, cv.CV_BGR2GRAY)
        cv.EqualizeHist(grayscale, grayscale)
        faces = cv.HaarDetectObjects(grayscale, Detector.cascade, cv.CreateMemStorage(), 1.1, 3, cv.CV_HAAR_DO_CANNY_PRUNING, (30, 30))

        if faces:
            for face in faces:
                left, top, width, height = face[0]
                top = self.__add_hair_offset(top, height)
                context['focal_points'].append(FocalPoint.from_square(left, top, width, height))
        else:
            self.next(context)
开发者ID:rootart,项目名称:thumbor,代码行数:17,代码来源:__init__.py


示例17: after_smart_detect

    def after_smart_detect(self, focal_points=[], points_from_storage=False):
        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)

        if self.running_smart_detection:
            self.should_run_image_operations = True
            return

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


示例18: adjust_focal_points

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

        self.focal_points = []

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

        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:MechanisM,项目名称:thumbor,代码行数:24,代码来源:transformer.py


示例19: test_new_point_from_dict

 def test_new_point_from_dict(self):
     point = FocalPoint.from_dict({'x': 10.1, 'y': 20.1, 'z': 5.1})
     expect(point.x).to_equal(10.1)
     expect(point.y).to_equal(20.1)
     expect(point.weight).to_equal(5.1)
开发者ID:GDxU,项目名称:thumbor,代码行数:5,代码来源:test_point.py


示例20: test_aligned_point_bottom_right

 def test_aligned_point_bottom_right(self):
     point = FocalPoint.from_alignment('right', 'bottom', 300, 200)
     expect(point.x).to_equal(300)
     expect(point.y).to_equal(200)
     expect(point.weight).to_equal(1.0)
开发者ID:GDxU,项目名称:thumbor,代码行数:5,代码来源:test_point.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python file_storage.Storage类代码示例发布时间:2022-05-27
下一篇:
Python http_loader.validate函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap