コード例 #1
0
ファイル: scan.py プロジェクト: jflesch/paperwork
    def __on_scan_info_cb(self, x, y):
        size = fit((x, y), self.canvas.visible_size)
        position = (
            int(self.position[0] + (self.canvas.visible_size[0] / 2) -
                (size[0] / 2)),
            int(self.position[1]),
        )

        scan_drawer = ScanAnimation(position, (x, y),
                                    self.canvas.visible_size)
        scan_drawer.set_canvas(self.canvas)
        ratio = scan_drawer.ratio

        self.scan_drawers = [scan_drawer]

        calibration = self.scan_workflow.calibration
        if calibration:
            calibration_drawer = TargetAreaDrawer(
                position, size,
                (
                    int(position[0] + (ratio * calibration[0][0])),
                    int(position[1] + (ratio * calibration[0][1])),
                ),
                (
                    int(ratio * (calibration[1][0] - calibration[0][0])),
                    int(ratio * (calibration[1][1] - calibration[0][1])),
                ),
            )
            calibration_drawer.set_canvas(self.canvas)

            self.scan_drawers.append(calibration_drawer)

        self.redraw()
コード例 #2
0
ファイル: scan.py プロジェクト: multimedix/paperwork
    def __on_ocr_done_cb(self, angle, img, boxes):
        self.animators = []

        drawers = self.ocr_drawers[angle]
        drawer = drawers[0]

        # we got our winner. Shoot the others
        self.ocr_drawers = {angle: [drawer]}

        new_size = fit(drawer.img_size, self.canvas.visible_size, force=True)
        new_position = (
            (self.position[0] + (self.canvas.visible_size[0] / 2) -
             (new_size[0] / 2)),
            (self.position[1]),
        )
        self.canvas.redraw()

        self.animators += [
            LinearCoordAnimator(drawer,
                                new_position,
                                self.SCAN_TO_OCR_ANIM_TIME,
                                attr_name='position',
                                canvas=self.canvas),
            LinearCoordAnimator(drawer,
                                new_size,
                                self.SCAN_TO_OCR_ANIM_TIME,
                                attr_name='size',
                                canvas=self.canvas),
        ]
        for animator in self.animators:
            animator.set_canvas(self.canvas)
        self.animators[-1].connect(
            'animator-end', lambda animator: GLib.idle_add(
                self.scan_workflow.on_ocr_anim_done, angle, img, boxes))
コード例 #3
0
ファイル: scan.py プロジェクト: multimedix/paperwork
    def __on_scan_info_cb(self, x, y):
        size = fit((x, y), self.canvas.visible_size)
        position = (
            int(self.position[0] + (self.canvas.visible_size[0] / 2) -
                (size[0] / 2)),
            int(self.position[1]),
        )

        scan_drawer = ScanAnimation(position, (x, y), self.canvas.visible_size)
        scan_drawer.set_canvas(self.canvas)
        ratio = scan_drawer.ratio

        self.scan_drawers = [scan_drawer]

        calibration = self.scan_workflow.calibration
        if calibration:
            calibration_drawer = TargetAreaDrawer(
                position,
                size,
                (
                    int(position[0] + (ratio * calibration[0][0])),
                    int(position[1] + (ratio * calibration[0][1])),
                ),
                (
                    int(ratio * (calibration[1][0] - calibration[0][0])),
                    int(ratio * (calibration[1][1] - calibration[0][1])),
                ),
            )
            calibration_drawer.set_canvas(self.canvas)

            self.scan_drawers.append(calibration_drawer)

        self.redraw()
コード例 #4
0
ファイル: scan.py プロジェクト: jflesch/paperwork
 def __on_process_done(self, img):
     size = fit(img.size, self.size)
     img = img.resize(size)
     self.drawers = [
         RectangleDrawer(self.position, self.size,
                         inside_color=ScanAnimation.BACKGROUND_COLOR),
         PillowImageDrawer(self.position, img)
     ]
     self.set_canvas(self.canvas)  # reset canvas on all new drawers
     self.canvas.redraw()
コード例 #5
0
 def __on_process_done(self, img):
     size = fit(img.size, self.size)
     img = img.resize(size)
     self.drawers = [
         RectangleDrawer(self.position, self.size,
                         inside_color=ScanAnimation.BACKGROUND_COLOR),
         PillowImageDrawer(self.position, img)
     ]
     self.set_canvas(self.canvas)  # reset canvas on all new drawers
     self.canvas.redraw()
コード例 #6
0
    def add_chunk(self, line, img_chunk):
        # big images take more time to draw
        # --> we resize it now
        img_size = fit(img_chunk.size, self.size)
        if (img_size[0] <= 0 or img_size[1] <= 0):
            return
        img_chunk = img_chunk.resize(img_size)

        surface = image2surface(img_chunk)
        self.surfaces.append((line * self.ratio, surface))
        self.on_tick()
コード例 #7
0
ファイル: animations.py プロジェクト: jflesch/paperwork
    def add_chunk(self, line, img_chunk):
        # big images take more time to draw
        # --> we resize it now
        img_size = fit(img_chunk.size, self.size)
        if (img_size[0] <= 0 or img_size[1] <= 0):
            return
        img_chunk = img_chunk.resize(img_size)

        surface = image2surface(img_chunk)
        self.surfaces.append((line * self.ratio, surface))
        self.on_tick()
コード例 #8
0
ファイル: scan.py プロジェクト: jflesch/paperwork
 def __on_scan_done(self, img):
     size = fit(img.size, self.size)
     img = img.resize(size)
     self.scan_animation = None
     self.drawers = [
         RectangleDrawer(self.position, self.size,
                         inside_color=ScanAnimation.BACKGROUND_COLOR),
         PillowImageDrawer(self.position, img),
         SpinnerAnimation(((self.position[0] + (self.size[0] / 2) -
                            SpinnerAnimation.ICON_SIZE / 2),
                           (self.position[1] + (self.size[1] / 2) -
                            SpinnerAnimation.ICON_SIZE / 2))),
     ]
     self.set_canvas(self.canvas)  # reset canvas on all new drawers
     self.canvas.redraw()
コード例 #9
0
 def __on_scan_done(self, img):
     size = fit(img.size, self.size)
     img = img.resize(size)
     self.scan_animation = None
     self.drawers = [
         RectangleDrawer(self.position, self.size,
                         inside_color=ScanAnimation.BACKGROUND_COLOR),
         PillowImageDrawer(self.position, img),
         SpinnerAnimation(((self.position[0] + (self.size[0] / 2) -
                            SpinnerAnimation.ICON_SIZE / 2),
                           (self.position[1] + (self.size[1] / 2) -
                            SpinnerAnimation.ICON_SIZE / 2))),
     ]
     self.set_canvas(self.canvas)  # reset canvas on all new drawers
     self.canvas.redraw()
コード例 #10
0
ファイル: scan.py プロジェクト: jflesch/paperwork
    def __on_ocr_done_cb(self, angle, img, boxes):
        self.animators = []

        drawers = self.ocr_drawers[angle]
        drawer = drawers[0]

        # we got our winner. Shoot the others
        self.ocr_drawers = {
            angle: [drawer]
        }

        new_size = fit(drawer.img_size, self.canvas.visible_size, force=True)
        new_position = (
            (self.position[0] + (self.canvas.visible_size[0] / 2) -
             (new_size[0] / 2)),
            (self.position[1]),
        )
        self.canvas.redraw()

        self.animators += [
            LinearCoordAnimator(
                drawer, new_position,
                self.SCAN_TO_OCR_ANIM_TIME,
                attr_name='position', canvas=self.canvas),
            LinearCoordAnimator(
                drawer, new_size,
                self.SCAN_TO_OCR_ANIM_TIME,
                attr_name='size', canvas=self.canvas),
        ]
        for animator in self.animators:
            animator.set_canvas(self.canvas)
        self.animators[-1].connect(
            'animator-end',
            lambda animator: GLib.idle_add(
                self.scan_workflow.on_ocr_anim_done,
                angle, img, boxes
            )
        )
コード例 #11
0
ファイル: scan.py プロジェクト: multimedix/paperwork
    def __on_ocr_started_cb(self, img):
        assert (self.canvas)

        if len(self.scan_drawers) > 0:
            if hasattr(self.scan_drawers[-1], 'target_size'):
                size = self.scan_drawers[-1].target_size
                position = self.scan_drawers[-1].target_position
            else:
                size = self.scan_drawers[-1].size
                position = self.scan_drawers[-1].position
            self.scan_drawers = []
        else:
            size = fit(img.size, self.canvas.visible_size)
            position = self.position

        target_sizes = self._compute_reduced_sizes(self.canvas.visible_size,
                                                   size)

        # animations with big images are too slow
        # --> reduce the image size
        img = img.resize(target_sizes)

        target_positions = self._compute_reduced_positions(
            self.canvas.visible_size, size, target_sizes)

        self.ocr_drawers = {}

        for angle in list(target_positions.keys()):
            drawer = PillowImageDrawer(position, img)
            drawer.set_canvas(self.canvas)
            self.ocr_drawers[angle] = [drawer]

        self.animators = []
        for (angle, drawers) in self.ocr_drawers.items():
            drawer = drawers[0]
            drawer.size = size
            logger.info("Animator: Angle %d: %s %s -> %s %s" %
                        (angle, str(drawer.position), str(drawer.size),
                         str(target_positions[angle]), str(target_sizes)))

            # reduce the rotation to its minimum
            anim_angle = angle % 360
            if (anim_angle > 180):
                anim_angle = -1 * (360 - anim_angle)

            new_animators = [
                LinearCoordAnimator(drawer,
                                    target_positions[angle],
                                    self.SCAN_TO_OCR_ANIM_TIME,
                                    attr_name='position',
                                    canvas=self.canvas),
                LinearCoordAnimator(drawer,
                                    target_sizes,
                                    self.SCAN_TO_OCR_ANIM_TIME,
                                    attr_name='size',
                                    canvas=self.canvas),
                LinearSimpleAnimator(drawer,
                                     anim_angle,
                                     self.SCAN_TO_OCR_ANIM_TIME,
                                     attr_name='angle',
                                     canvas=self.canvas),
            ]
            # all the animators last the same length of time
            # so any of them is good enough for this signal
            new_animators[0].connect(
                'animator-end', lambda animator: GLib.idle_add(
                    self.__on_ocr_rotation_anim_done_cb))
            self.animators += new_animators
コード例 #12
0
ファイル: scan.py プロジェクト: jflesch/paperwork
    def __on_ocr_started_cb(self, img):
        assert(self.canvas)

        if len(self.scan_drawers) > 0:
            if hasattr(self.scan_drawers[-1], 'target_size'):
                size = self.scan_drawers[-1].target_size
                position = self.scan_drawers[-1].target_position
            else:
                size = self.scan_drawers[-1].size
                position = self.scan_drawers[-1].position
            self.scan_drawers = []
        else:
            size = fit(img.size, self.canvas.visible_size)
            position = self.position

        target_sizes = self._compute_reduced_sizes(
            self.canvas.visible_size, size)

        # animations with big images are too slow
        # --> reduce the image size
        img = img.resize(target_sizes)

        target_positions = self._compute_reduced_positions(
            self.canvas.visible_size, size, target_sizes)

        self.ocr_drawers = {}

        for angle in list(target_positions.keys()):
            drawer = PillowImageDrawer(position, img)
            drawer.set_canvas(self.canvas)
            self.ocr_drawers[angle] = [drawer]

        self.animators = []
        for (angle, drawers) in self.ocr_drawers.items():
            drawer = drawers[0]
            drawer.size = size
            logger.info("Animator: Angle %d: %s %s -> %s %s"
                        % (angle,
                           str(drawer.position), str(drawer.size),
                           str(target_positions[angle]),
                           str(target_sizes)))

            # reduce the rotation to its minimum
            anim_angle = angle % 360
            if (anim_angle > 180):
                anim_angle = -1 * (360 - anim_angle)

            new_animators = [
                LinearCoordAnimator(
                    drawer, target_positions[angle],
                    self.SCAN_TO_OCR_ANIM_TIME,
                    attr_name='position', canvas=self.canvas),
                LinearCoordAnimator(
                    drawer, target_sizes,
                    self.SCAN_TO_OCR_ANIM_TIME,
                    attr_name='size', canvas=self.canvas),
                LinearSimpleAnimator(
                    drawer, anim_angle,
                    self.SCAN_TO_OCR_ANIM_TIME,
                    attr_name='angle', canvas=self.canvas),
            ]
            # all the animators last the same length of time
            # so any of them is good enough for this signal
            new_animators[0].connect(
                'animator-end', lambda animator:
                GLib.idle_add(self.__on_ocr_rotation_anim_done_cb))
            self.animators += new_animators