How to use the pyocr.PyocrException function in pyocr

To help you get started, we’ve selected a few pyocr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpaperwork / pyocr / tests / tests_libtesseract.py View on Github external
def test_nolangs(self):
        """
        Issue #51: Running OCR without any language installed causes a SIGSEGV.
        """
        tessdata_prefix = os.getenv("TESSDATA_PREFIX", "")
        os.environ['TESSDATA_PREFIX'] = '/opt/tulipe'
        try:
            with self.assertRaises(PyocrException):
                self.tool.image_to_string(
                    PIL.Image.open(self._path_to_img('test-japanese.jpg')),
                    lang='fra'
                )
        finally:
            if tessdata_prefix == "":
                os.environ['TESSDATA_PREFIX'] = ""
                os.unsetenv("TESSDATA_PREFIX")
            else:
                os.environ['TESSDATA_PREFIX'] = tessdata_prefix
github openpaperwork / pyocr / tests / tests_libtesseract.py View on Github external
def test_nolangs2(self):
        with self.assertRaises(PyocrException):
            self.tool.image_to_string(
                PIL.Image.open(self._path_to_img('test-japanese.jpg')),
                lang='doesnotexist'
            )
github lucab85 / PDFtoTXT / LocalOCR.py View on Github external
def image2txt_pyocr(self, image, do_orientation):
        txt = ""
        orientation = ""
        img_per_page = PI.open(io.BytesIO(image))

        if do_orientation is True:
            try:
                if self.tool.can_detect_orientation():
                    orientation = self.tool.detect_orientation(img_per_page, lang=self.lang)
                    angle = orientation["angle"]
                    if angle != 0:
                        img_per_page.rotate(orientation["angle"])
            except pyocr.PyocrException as exc:
                print("Orientation detection failed: {}".format(exc))
            print("Orientation: {}".format(orientation))

        try:
            txt = self.tool.image_to_string(
                img_per_page, lang=self.lang,
                builder=pyocr.builders.TextBuilder()
            )
        except pyocr.error.TesseractError as e:
            print("{}".format(e))
        return txt