示例#1
0
            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)
示例#2
0
 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
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    async def detect(self):
        features = self.get_features()

        if features:
            for square, _ in features:
                self.context.request.focal_points.append(
                    FocalPoint.from_square(*square))
        else:
            await self.next()  # pylint: disable=not-callable
示例#6
0
    def focal_point(self, overall_width, overall_height):

        bbox = self.api_resp['BoundingBox']
        x = int(bbox['Left'] * overall_width)
        y = int(bbox['Top'] * overall_height)
        w = int(bbox['Width'] * overall_width)
        h = int(bbox['Height'] * overall_height)

        return FocalPoint.from_square(x, y, w, h, origin='RekognitionDetector')
示例#7
0
    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)
示例#8
0
        def config_context(context):
            image_w, image_h = expected.size[0], expected.size[1]
            point = FocalPoint.from_square(50,
                                           50,
                                           image_w - 100,
                                           image_h - 100,
                                           origin="Face Detection")

            context.request.focal_points = [point]
示例#9
0
 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
示例#10
0
文件: __init__.py 项目: APSL/thumbor
    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)
示例#11
0
    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)
示例#12
0
    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
示例#13
0
    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")
                )
示例#14
0
文件: focal.py 项目: 5um1th/thumbor
    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")
                )
示例#15
0
    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)
示例#16
0
    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)
示例#17
0
    async def detect(self):
        try:
            features = self.get_features()
        except Exception as error:
            logger.exception(error)
            logger.warning("Error during face detection; skipping to next detector")
            return await self.next()

        if features:
            for (left, top, width, height), _ 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"
                    )
                )
            return

        await self.next()
示例#18
0
    async def detect(self):
        if not self.verify_cv():
            await self.next()

            return

        features = self.get_features()

        if not features:
            await self.next()  # pylint: disable=not-callable

        for (left, top, width, height), _ in features:
            offset = self.get_detection_offset(left, top, width, height)
            self.context.request.focal_points.append(
                FocalPoint.from_square(
                    left + offset.get("left", 0.0),
                    top + offset.get("top", 0.0),
                    width + offset.get("right", 0.0),
                    height + offset.get("bottom", 0.0),
                    origin=self.get_origin(),
                ))
示例#19
0
 def test_new_point_square_point(self):
     point = FocalPoint.from_square(x=350, y=50, width=110, height=110)
     expect(point.x).to_equal(405)
     expect(point.y).to_equal(105)
     expect(point.weight).to_equal(12100)
示例#20
0
 def test_new_point_square_point(self):
     point = FocalPoint.from_square(x=350, y=50, width=110, height=110)
     expect(point.x).to_equal(405)
     expect(point.y).to_equal(105)
     expect(point.weight).to_equal(12100)
示例#21
0
        def config_context(context):
            image_w, image_h = expected.size[0], expected.size[1]
            point = FocalPoint.from_square(50, 50, image_w - 100, image_h - 100, origin='Face Detection')

            context.request.focal_points = [point]
示例#22
0
 def topic(self):
     return FocalPoint.from_square(0, 300, 300, 300)
示例#23
0
 def topic(self):
     return FocalPoint.from_square(x=350, y=50, width=110, height=110)
示例#24
0
 def topic(self):
     return FocalPoint.from_square(350, 50, 110, 110)
示例#25
0
def test_from_square():
    point = FocalPoint.from_square(x=10.0, y=20.0, width=100, height=200)
    assert point.x == 55.0
    assert point.y == 110.0
    assert point.weight == 20000.0
示例#26
0
 def topic(self):
     return FocalPoint.from_square(x=350, y=50, width=110, height=110)
示例#27
0
def test_from_square():
    point = FocalPoint.from_square(x=10.0, y=20.0, width=100, height=200)
    assert point.x == 55.0
    assert point.y == 110.0
    assert point.weight == 20000.0