Commit 06d1b6e9 authored by Jerome Flesch's avatar Jerome Flesch

Tesseract C-API: Fix orientation detection

Signed-off-by: Jerome Flesch's avatarJerome Flesch <jflesch@gmail.com>
parent cca1df11
...@@ -53,9 +53,9 @@ def can_detect_orientation(): ...@@ -53,9 +53,9 @@ def can_detect_orientation():
def detect_orientation(image, lang=None): def detect_orientation(image, lang=None):
handle = tesseract_raw.init(lang=lang) handle = tesseract_raw.init(lang=lang)
try: try:
tesseract_raw.set_page_seg_mode( #tesseract_raw.set_page_seg_mode(
handle, tesseract_raw.PageSegMode.OSD_ONLY # handle, tesseract_raw.PageSegMode.OSD_ONLY
) #)
tesseract_raw.set_image(handle, image) tesseract_raw.set_image(handle, image)
tesseract_raw.recognize(handle) tesseract_raw.recognize(handle)
page_iterator = tesseract_raw.analyse_layout(handle) page_iterator = tesseract_raw.analyse_layout(handle)
...@@ -64,7 +64,7 @@ def detect_orientation(image, lang=None): ...@@ -64,7 +64,7 @@ def detect_orientation(image, lang=None):
"failed", "Orientation detection failed. No script ?" "failed", "Orientation detection failed. No script ?"
) )
try: try:
orientation = page_iterator_orientation(page_iterator) orientation = tesseract_raw.page_iterator_orientation(page_iterator)
angle = { angle = {
tesseract_raw.Orientation.PAGE_UP: 0, tesseract_raw.Orientation.PAGE_UP: 0,
tesseract_raw.Orientation.PAGE_RIGHT: 90, tesseract_raw.Orientation.PAGE_RIGHT: 90,
......
...@@ -200,7 +200,7 @@ def set_image(handle, image): ...@@ -200,7 +200,7 @@ def set_image(handle, image):
image = image.convert("RGB") image = image.convert("RGB")
image.load() image.load()
imgdata = image.tobytes() imgdata = image.tobytes("raw", "RGB")
imgsize = image.size imgsize = image.size
...@@ -250,10 +250,10 @@ def page_iterator_orientation(iterator): ...@@ -250,10 +250,10 @@ def page_iterator_orientation(iterator):
g_libtesseract.TessPageIteratorOrientation( g_libtesseract.TessPageIteratorOrientation(
iterator, iterator,
ctypes.POINTER(orientation), ctypes.pointer(orientation),
ctypes.POINTER(writing_direction), ctypes.pointer(writing_direction),
ctypes.POINTER(textline_order), ctypes.pointer(textline_order),
ctypes.POINTER(deskew_angle) ctypes.pointer(deskew_angle)
) )
return { return {
......
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