Exemplo n.º 1
0
    def __recognizeImageFromBounds(self, image, bounds, page_resolution):
        clip = image.crop(bounds)
        text = clip_type = None
        language = ''
        if self.ocr_engine:
            language = self.ocr_engine.getLanguage()
            text = self.readImage(clip)
            clip_type = self.ocr_engine.classify(text)

        x0, y0, x1, y1 = bounds
        x, y, width, height = graphics.getBoundsFromStartEndPoints((x0, y0),
                                                                   (x1, y1))

        data_box = DataBox(x, y, width, height, clip)
        data_box.setLanguage(language)
        if text:
            data_box.setText(text)
            data_box.setType(clip_type)

        if clip.mode == 'L':
            grayscale_clip = clip
        else:
            grayscale_clip = clip.convert('L')
        text_size = self.getTextSizeFromImage(grayscale_clip, page_resolution)

        if text_size:
            data_box.setFontSize(text_size)

        return data_box
Exemplo n.º 2
0
    def __recognizeImageFromBounds(self, image, bounds, page_resolution):
        clip = image.crop(bounds)
        text = clip_type = None
        language = ''
        if self.ocr_engine:
            language = self.ocr_engine.getLanguage()
            text = self.readImage(clip)
            clip_type = self.ocr_engine.classify(text)

        x0, y0, x1, y1 = bounds
        x, y, width, height = graphics.getBoundsFromStartEndPoints((x0, y0),
                                                                   (x1, y1))

        data_box = DataBox(x, y, width, height, clip)
        data_box.setLanguage(language)
        if text:
            data_box.setText(text)
            data_box.setType(clip_type)

        if clip.mode == 'L':
            grayscale_clip = clip
        else:
            grayscale_clip = clip.convert('L')
        text_size = self.getTextSizeFromImage(grayscale_clip, page_resolution)

        if text_size:
            data_box.setFontSize(text_size)

        return data_box