Comments (13)
AnalyseLayout
returns:
Page iterator or None on error or an empty page.
So you need to check if the returned value is not None before calling Orientation
.
from tesserocr.
Right, it
is None
. But rotating an image 3 deg shouldn't cause that to happen correct?
from tesserocr.
Also, just tested via the c-api
and it works fine. So not an issue with tesseract
or leptonica
.
from tesserocr.
If you look at the source code linked in my previous comment, all it does is call the respective AnalyseLayout
C function and if its value is NULL
returns None
. Is it possible that you're getting None
due to the issue in #4?
from tesserocr.
See #5 (comment)
Here's part of the working code if it helps
def get_native_orientation(tesseract, leptonica, api, path, mode=PAGE_MODE):
tesseract.TessBaseAPISetPageSegMode(api, mode)
pix = leptonica.pixRead(path)
tesseract.TessBaseAPISetImage2(api, pix)
if tesseract.TessBaseAPIRecognize(api, None):
leptonica.pixDestroy(byref(pix))
tesseract.TessBaseAPIDelete(api)
raise Exception('Tesseract recognition failed')
it = tesseract.TessBaseAPIAnalyseLayout(api)
orientation, direction, line_order = c_int(), c_int(), c_int()
skew = c_float()
tesseract.TessPageIteratorOrientation(
it, byref(orientation), byref(direction), byref(line_order),
byref(skew))
return orientation.value, direction.value, line_order.value, skew.value
from tesserocr.
Alright, the problem seems to be with the usage of PIL.Image
. If you use the SetImageFile
method instead of SetImage
it'll work. I'm going to debug this issue and apply the appropriate fix.
from tesserocr.
Hey could you please test with the latest commit? It should now work as expected with PIL images.
from tesserocr.
it works, thanks! Can you let me know once you publish the new version?
from tesserocr.
Another issue tho. It works for 3deg and 4deg, but crashes when the image is rotated 5deg. And fwiw, the c-api
crashes as well with Segmentation fault: 11
.
from tesserocr.
With the 5 degrees tilt, tesseract fails to detect any text in the image (try tesseract eurotext_ang.tiff -
) so this isn't related to the issue we fixed here.
Note that the tesseract
executable applies a different logic to output the orientation when -psm 0
is specified. In our case we're using psm 1
and given that no text is detected, AnalyseLayout
returns None
.
Unfortunately, I didn't expose the DetectOS
which is used in tesseract 3.04.00 to write the same logic in tesserocr
. The nice thing is they made it much easier to do in tesseract 3.04.01 but implementing it will break compatibility with version 3.04.00 so I'm gonna see how to do it properly while maintaining backward compatibility (preferably with 3.02 as well).
from tesserocr.
So does that explain why running the script with psm=0 returns null
results? I wasnt aware of 'DetectOS' but it looks like it may be what i
need.
CR #6
from tesserocr.
Yes certainly does, seems that AnalyseLayout
always returns None when psm is 0. Orientation needs to be detected differently when psm is 0, I'm going to work on it with support for 3.04.00 and the newer 3.04.01 as well, will let you know once it's ready.
from tesserocr.
Hello, Anyone can help with my conversion of C/C++ tesseract-ocr code to Python?
https://stackoverflow.com/questions/60166781/ctypesconvert-the-c-c-tesseract-ocr-code-to-python
from tesserocr.
Related Issues (20)
- Failed to init API, possibly an invalid tessdata path: ./ HOT 3
- ImportError: dlopen HOT 4
- Publish wheels for aarch64 HOT 2
- symbol not found in flat namespace HOT 7
- `GetTextDirection` + `MapWordConfidences` crash python HOT 2
- in loop `GetChoiceIterator` crashs python if result is empty
- `GetDatapath` can't find the default path that tesseract should find on windows HOT 7
- `MapWordConfidences` throw 'No text returned' when the result is empty
- ImportError: DLL load failed while importing tesserocr: The specified module could not be found. HOT 6
- Side effects of running tesserocr-recognize as a worker HOT 1
- Can't directly use image_to_text for invalid path for tessdata. HOT 2
- Segfault when used with PyMuPDF (aka fitz) HOT 1
- tesserocr.tesseract_version() Missing Libaries HOT 2
- can't ocr anything with 2.6.2 HOT 2
- Missing support for Tesseract5? HOT 18
- No definition found for "tesserocr" HOT 2
- user patterns are not considered HOT 4
- does not build on current Tesseract anymore HOT 8
- Problem with API HOT 2
- Allow to show tesseract and leptonica messages (easily) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tesserocr.