Exemplo n.º 1
0
        def topic(self):
            engine = MockEngine(size=IMAGE_SIZE)
            json = JSONEngine(engine=engine, path=IMAGE_PATH)

            json.focus([FocalPoint(100, 100), FocalPoint(200, 200)])

            return loads(json.read('jpg', 100))
Exemplo n.º 2
0
    def detect(self, callback):
        engine = self.context.modules.engine
        sz = engine.size
        image = cv.CreateImageHeader(sz, cv.IPL_DEPTH_8U, 3)
        cv.SetData(image, engine.get_image_data())

        gray_image = cv.CreateImage(engine.size, 8, 1)
        convert_mode = getattr(cv, 'CV_%s2GRAY' % engine.get_image_mode())
        cv.CvtColor(image, gray_image, convert_mode)
        image = gray_image
        rows = sz[0]
        cols = sz[1]

        eig_image = cv.CreateMat(rows, cols, cv.CV_32FC1)
        temp_image = cv.CreateMat(rows, cols, cv.CV_32FC1)
        points = cv.GoodFeaturesToTrack(image,
                                        eig_image,
                                        temp_image,
                                        20,
                                        0.04,
                                        1.0,
                                        useHarris=False)

        if points:
            for x, y in points:
                self.context.request.focal_points.append(FocalPoint(x, y, 1))
            callback()
        else:
            self.next(callback)
Exemplo n.º 3
0
    def detect(self, callback):
        engine = self.context.modules.engine
        try:
            img = np.array(
                engine.convert_to_grayscale(update_image=False,
                                            with_alpha=False))
        except Exception as e:
            logger.exception(e)
            logger.warn(
                'Error during feature detection; skipping to next detector')
            self.next(callback)
            return

        points = cv2.goodFeaturesToTrack(
            img,
            maxCorners=20,
            qualityLevel=0.04,
            minDistance=1.0,
            useHarrisDetector=False,
        )
        if points is not None:
            for point in points:
                x, y = point.ravel()
                self.context.request.focal_points.append(
                    FocalPoint(x.item(), y.item(), 1))
            callback()
        else:
            self.next(callback)
Exemplo n.º 4
0
    async def detect(self):
        engine = self.context.modules.engine
        try:
            img = np.array(
                engine.convert_to_grayscale(update_image=False, alpha=False))
        except Exception as error:
            logger.exception(error)
            logger.warning(
                "Error during feature detection; skipping to next detector")
            return await self.next()  # pylint: disable=not-callable

        points = cv2.goodFeaturesToTrack(  # pylint: disable=no-member
            img,
            maxCorners=20,
            qualityLevel=0.04,
            minDistance=1.0,
            useHarrisDetector=False,
        )
        if points is not None:
            for point in points:
                x_pos, y_pos = point.ravel()
                self.context.request.focal_points.append(
                    FocalPoint(x_pos.item(), y_pos.item(), 1))
            return

        await self.next()  # pylint: disable=not-callable
Exemplo n.º 5
0
    def detect(self, callback):
        engine = self.context.modules.engine
        img = np.array(
            engine.convert_to_grayscale(update_image=False, with_alpha=False))

        points = cv2.goodFeaturesToTrack(
            img,
            maxCorners=20,
            qualityLevel=0.04,
            minDistance=1.0,
            useHarrisDetector=False,
        )
        if points is not None:
            for x, y in points.squeeze():
                self.context.request.focal_points.append(FocalPoint(x, y, 1))
            callback()
        else:
            self.next(callback)
Exemplo n.º 6
0
 def test_new_point_weighted(self):
     point = FocalPoint(x=10, y=20, height=1.0, width=3.0, weight=3.0)
     expect(point.weight).to_equal(3.0)
     expect(str(point)).to_equal(
         'FocalPoint(x: 10, y: 20, width: 3, height: 1, weight: 3, origin: alignment)'
     )
Exemplo n.º 7
0
 def test_new_point_default_weight(self):
     point = FocalPoint(10, 20)
     expect(point.x).to_equal(10)
     expect(point.y).to_equal(20)
Exemplo n.º 8
0
 def topic(self):
     return FocalPoint(x=10,
                       y=20,
                       height=1.0,
                       width=3.0,
                       weight=3.0)
Exemplo n.º 9
0
 def topic(self):
     return FocalPoint(10, 20)
Exemplo n.º 10
0
def test_default_weight_is_one():
    point = FocalPoint(x=10.0, y=20.0)

    assert point.weight == 1.0
Exemplo n.º 11
0
def test_focal_point():
    point = FocalPoint(x=10.0, y=20.0, weight=3.4)

    assert point.x == 10.0
    assert point.y == 20.0
    assert point.weight == 3.4