Commit ff9584a7 authored by Jerome Flesch's avatar Jerome Flesch

Rename 'tesseract_capi' into 'libtesseract'

Signed-off-by: Jerome Flesch's avatarJerome Flesch <jflesch@gmail.com>
parent f4a54d32
......@@ -6,12 +6,12 @@ import unittest
from pyocr import cuneiform_sh
from pyocr import pyocr
from pyocr import tesseract_capi
from pyocr import libtesseract
from pyocr import tesseract_sh
from tests import tests_cuneiform
from tests import tests_tesseract
from tests import tests_tesseract_capi
from tests import tests_libtesseract
if __name__ == '__main__':
for tool in pyocr.TOOLS:
......@@ -28,10 +28,10 @@ if __name__ == '__main__':
print("OCR tool found:")
for tool in pyocr.get_available_tools():
print("- %s" % tool.get_name())
if tesseract_capi.is_available():
if libtesseract.is_available():
print("---")
print("Tesseract C-API:")
unittest.TextTestRunner().run(tests_tesseract_capi.get_all_tests())
unittest.TextTestRunner().run(tests_libtesseract.get_all_tests())
if tesseract_sh.is_available():
print("---")
print("Tesseract SH:")
......
#!/usr/bin/env python3
'''
tesseract_capi/ is a wrapper for google's Tesseract-OCR C API
libtesseract/ is a wrapper for google's Tesseract-OCR C API
( http://code.google.com/p/tesseract-ocr/ ).
USAGE:
......@@ -14,8 +14,6 @@ PyOCR is released under the GPL v3.
Copyright (c) Jerome Flesch, 2011-2012
https://github.com/jflesch/pyocr#readme
'''
import sys
from .. import builders
from . import tesseract_raw
......@@ -120,7 +118,8 @@ def image_to_string(image, lang=None, builder=None):
builder.start_line(box)
last_word_in_line = tesseract_raw.page_iterator_is_at_final_element(
page_iterator, lvl_line, lvl_word)
page_iterator, lvl_line, lvl_word
)
word = tesseract_raw.result_iterator_get_utf8_text(
res_iterator, lvl_word
......
......@@ -46,7 +46,7 @@ https://github.com/jflesch/python-tesseract#readme
"""
from . import cuneiform_sh
from . import tesseract_capi
from . import libtesseract
from . import tesseract_sh
__all__ = [
......@@ -57,7 +57,7 @@ __all__ = [
TOOLS = [ # in preference order
tesseract_capi,
libtesseract,
tesseract_sh,
cuneiform_sh,
]
......
......@@ -8,7 +8,7 @@ import tempfile
import unittest
from pyocr import builders
from pyocr import tesseract_capi
from pyocr import libtesseract
class TestContext(unittest.TestCase):
......@@ -20,13 +20,13 @@ class TestContext(unittest.TestCase):
def test_available(self):
self.assertTrue(
tesseract_capi.is_available(),
libtesseract.is_available(),
"Tesseract not found."
" Are libtesseract and libleptonica installed ? "
)
def test_version(self):
self.assertTrue(tesseract_capi.get_version() in (
self.assertTrue(libtesseract.get_version() in (
(3, 2, 1),
(3, 2, 2),
(3, 3, 0),
......@@ -35,7 +35,7 @@ class TestContext(unittest.TestCase):
" (3.4.0) ! Some tests will be skipped !"))
def test_langs(self):
langs = tesseract_capi.get_available_languages()
langs = libtesseract.get_available_languages()
self.assertTrue("eng" in langs,
("English training does not appear to be installed."
" (required for the tests)"))
......@@ -60,7 +60,7 @@ class TestTxt(unittest.TestCase):
def __test_txt(self, image_file, expected_output_file, lang='eng'):
image_file = "tests/data/" + image_file
expected_output_file = "tests/tesseract_capi/" + expected_output_file
expected_output_file = "tests/libtesseract/" + expected_output_file
expected_output = ""
with codecs.open(expected_output_file, 'r', encoding='utf-8') \
......@@ -69,7 +69,7 @@ class TestTxt(unittest.TestCase):
expected_output += line
expected_output = expected_output.strip()
output = tesseract_capi.image_to_string(
output = libtesseract.image_to_string(
Image.open(image_file), lang=lang
)
......@@ -100,14 +100,14 @@ class TestWordBox(unittest.TestCase):
def __test_txt(self, image_file, expected_box_file, lang='eng'):
image_file = "tests/data/" + image_file
expected_box_file = "tests/tesseract_capi/" + expected_box_file
expected_box_file = "tests/libtesseract/" + expected_box_file
with codecs.open(expected_box_file, 'r', encoding='utf-8') \
as file_descriptor:
expected_boxes = self.builder.read_file(file_descriptor)
expected_boxes.sort()
boxes = tesseract_capi.image_to_string(
boxes = libtesseract.image_to_string(
Image.open(image_file), lang=lang, builder=self.builder
)
boxes.sort()
......@@ -139,7 +139,7 @@ class TestWordBox(unittest.TestCase):
self.__test_txt('test-japanese.jpg', 'test-japanese.words', 'jpn')
def test_write_read(self):
original_boxes = tesseract_capi.image_to_string(
original_boxes = libtesseract.image_to_string(
Image.open("tests/data/test.png"), builder=self.builder
)
self.assertTrue(len(original_boxes) > 0)
......@@ -174,9 +174,9 @@ class TestLineBox(unittest.TestCase):
def __test_txt(self, image_file, expected_box_file, lang='eng'):
image_file = "tests/data/" + image_file
expected_box_file = "tests/tesseract_capi/" + expected_box_file
expected_box_file = "tests/libtesseract/" + expected_box_file
boxes = tesseract_capi.image_to_string(
boxes = libtesseract.image_to_string(
Image.open(image_file), lang=lang,
builder=self.builder
)
......@@ -208,7 +208,7 @@ class TestLineBox(unittest.TestCase):
self.__test_txt('test-japanese.jpg', 'test-japanese.lines', 'jpn')
def test_write_read(self):
original_boxes = tesseract_capi.image_to_string(
original_boxes = libtesseract.image_to_string(
Image.open("tests/data/test.png"), builder=self.builder)
self.assertTrue(len(original_boxes) > 0)
......@@ -235,16 +235,16 @@ class TestLineBox(unittest.TestCase):
class TestOrientation(unittest.TestCase):
def test_can_detect_orientation(self):
self.assertTrue(tesseract_capi.can_detect_orientation())
self.assertTrue(libtesseract.can_detect_orientation())
def test_orientation_0(self):
img = Image.open('tests/data/test.png')
result = tesseract_capi.detect_orientation(img, lang='eng')
result = libtesseract.detect_orientation(img, lang='eng')
self.assertEqual(result['angle'], 0)
def test_orientation_90(self):
img = Image.open('tests/data/test-90.png')
result = tesseract_capi.detect_orientation(img, lang='eng')
result = libtesseract.detect_orientation(img, lang='eng')
self.assertEqual(result['angle'], 90)
......
......@@ -41,13 +41,13 @@ run_tess_capi()
cat << EOF | python3
from PIL import Image
from pyocr import tesseract_capi
from pyocr import libtesseract
from pyocr import builders
img = Image.open("${img}")
builder = builders.${builder}()
out = tesseract_capi.image_to_string(img, lang="${lang}", builder=builder)
out = libtesseract.image_to_string(img, lang="${lang}", builder=builder)
with open("${out}", "w") as fd:
builder.write_file(fd, out)
......@@ -86,18 +86,18 @@ cp tesseract/test-japanese.words tesseract/test-japanese.lines
echo "=== Tesseract C-api ==="
run_tess_capi data/test.png tesseract_capi/test.txt eng TextBuilder
run_tess_capi data/test.png tesseract_capi/test.words eng WordBoxBuilder
run_tess_capi data/test.png tesseract_capi/test.lines eng LineBoxBuilder
run_tess_capi data/test.png libtesseract/test.txt eng TextBuilder
run_tess_capi data/test.png libtesseract/test.words eng WordBoxBuilder
run_tess_capi data/test.png libtesseract/test.lines eng LineBoxBuilder
run_tess_capi data/test-european.jpg tesseract_capi/test-european.txt eng TextBuilder
run_tess_capi data/test-european.jpg tesseract_capi/test-european.words eng WordBoxBuilder
run_tess_capi data/test-european.jpg tesseract_capi/test-european.lines eng LineBoxBuilder
run_tess_capi data/test-european.jpg libtesseract/test-european.txt eng TextBuilder
run_tess_capi data/test-european.jpg libtesseract/test-european.words eng WordBoxBuilder
run_tess_capi data/test-european.jpg libtesseract/test-european.lines eng LineBoxBuilder
run_tess_capi data/test-french.jpg tesseract_capi/test-french.txt fra TextBuilder
run_tess_capi data/test-french.jpg tesseract_capi/test-french.words fra WordBoxBuilder
run_tess_capi data/test-french.jpg tesseract_capi/test-french.lines fra LineBoxBuilder
run_tess_capi data/test-french.jpg libtesseract/test-french.txt fra TextBuilder
run_tess_capi data/test-french.jpg libtesseract/test-french.words fra WordBoxBuilder
run_tess_capi data/test-french.jpg libtesseract/test-french.lines fra LineBoxBuilder
run_tess_capi data/test-japanese.jpg tesseract_capi/test-japanese.txt jpn TextBuilder
run_tess_capi data/test-japanese.jpg tesseract_capi/test-japanese.words jpn WordBoxBuilder
run_tess_capi data/test-japanese.jpg tesseract_capi/test-japanese.lines jpn LineBoxBuilder
run_tess_capi data/test-japanese.jpg libtesseract/test-japanese.txt jpn TextBuilder
run_tess_capi data/test-japanese.jpg libtesseract/test-japanese.words jpn WordBoxBuilder
run_tess_capi data/test-japanese.jpg libtesseract/test-japanese.lines jpn LineBoxBuilder
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment