Comments (22)
@sirfz Yes it solved the problem thanks for your help ;)
from tesserocr.
Both ubuntu and mac use en_US.UTF-8. It's magic.
from tesserocr.
Interesting, this usually means the returned string is not a valid UTF-8 string. Can you try the same image with the tesseract CLI tool? Also, if you don't mind, can you share the image so I can reproduce the error?
In addition to the above, please share your Cython version as well.
from tesserocr.
Thanks for taking the time !
The tesseract CLI actually works with the option -l fra so I don't think it comes from tesseract itself.
Here is the image I'm testing :
cython.version
'0.25.2'
from tesserocr.
Just tested it with the latest tesserocr version from the tesseract4 branch and had no problems (although I have the alpha tesseract 4.0 version installed):
In [1]: import tesserocr
In [2]: from PIL import Image
In [3]: api = tesserocr.PyTessBaseAPI(lang='fra')
In [4]: image = Image.open('524666a2-34f0-11e7-9022-8fb02881b33a.jpg')
In [5]: api.SetImage(image)
In [6]: api.SetSourceResolution(300)
In [7]: api.GetUTF8Text()
Out[7]: u'SYNO240 - BES 15-11 /15\n\nAFFILIATION SALARI\xc9\nQPDF IL ENSEMBLE DU PERSONNEL\n\nSANT\xc9 BUREAUX D\'\xc9TUDES\nSOCGLE COLLECTIF\n\n \n\n \n\nJe b\xe9n\xe9ficie uniquement A LUNE\n13 du contrat sant\xe9 souscrit par mon\nentreprise : mon conjoint n\'est pas couvert par ce\ncontrat.\n\n \n\n \n\n \n\n \n\n \n\nJe souhaite \xe9tendre mes garanties \xe0 mon\n\nconjoint :\ne compl\xe9te; la demande .d\u2019adh\xe9sion\ncm d \xab Extension des garanties Socle\nl\u2014 ; \xe0 mon conjoint\n\n \n\nJe souhaite renforcer mes garanties\net celles de mes ayants droit :\n\n\xab! "compl\xe9tez la demande d\'adh\xe9sion\nw \xab Renforts de garanties \xbb\n\n \n\na Je date et je signe chaque page\n\na Je choisis mon mode de paiement\n\xab Je fournis, pour chaque personne affili\xe9e, une photocopie d\'attestation de droits de la S\xe9curit\xe9 sociale\n\na Je joins un relev\xe9 d\'identit\xe9 bancaire pour le versement des prestations\na Je transmets le tout \xe0 mon employeur\n\nD\xe8s le lendemain du traitement du dossier, vous pouvez t\xe9l\xe9charger sur votre Espace Assur\xe9\nsur www.april-entreprise-prevoyance.fr :\na Votre certificat d\'affiliation au Socle,\n\na Le r\xe9sum\xe9 des garanties souscrites,\na Un exemplaire des Notices valant Conditions G\xe9n\xe9rales remises \xe0 l\'adh\xe9sion.\n\n \n\nVous recevrez par courrier :\n\na Votre carte de Tiers-payant, en 2 exemplaires,\na Vos certificats d\'adh\xe9sion extension et / ou renfort de garanties avec votre \xe9ch\xe9ancier de paiement\n(uniquement si ces options sont souscrites).\n\n'
In [8]: tesserocr.__version__
Out[8]: '2.2.0-beta2'
In [9]: tesserocr.tesseract_version()
Out[9]: u'tesseract 4.00.00alpha\n leptonica-1.74\n libjpeg 8d (libjpeg-turbo 1.5.0) : libpng 1.6.28 : libtiff 4.0.7 : zlib 1.2.11\n'
Try installing the new tesserocr version and test it in your environment to see if it's already solved.
from tesserocr.
Upgrading to tesseract 4.0 solved the problem 👍 but now I got an install issue on your new tesserocr version. I posted the issue on #26.
Thanks for the help !
from tesserocr.
Actually I wanted you to test the latest tesserocr from the tesseract4 branch with your current tesseract installation, and not upgrade tesseract as this error shouldn't happen regardless of the tesseract version. Also note that tesseract v4 is still an alpha version.
I'm reopening this issue until I can test it with your version of tesseract and see if I can reproduce it.
from tesserocr.
It seems that upgrading only tesserocr solved the problem as I'm not able to reproduce the error.
from tesserocr.
So you tested tesserocr 2.2 with tesseract 3.05 and it's working now? If so please go ahead and close this issue if you believe it's resolved.
from tesserocr.
Hi @sirfz the issue is back again. I tried to extract text fo some image and when I called the GetUTF8 method I get UnicodeDecodeError.
My installation is
tesserocr 2.2.0-rc2 and
tesserocr.tesseract_version()
'tesseract 3.05.00\n leptonica-1.74.1\n libjpeg 8d : libpng 1.6.29 : libtiff 4.0.7 : zlib 1.2.8\n'
And this is the image
Thanks for your help
from tesserocr.
Are you sure you're getting that error from tesserocr? Couldn't reproduce the problem:
In [1]: import tesserocr
In [2]: api = tesserocr.PyTessBaseAPI(lang='fra')
In [3]: api.SetImageFile('Downloads/27095236-3554bb50-506d-11e7-9d0d-5b993f230992.jpg')
In [4]: print api.GetUTF8Text().strip()
Santé Bureaux d'études 1/3
Collège Ensemble du personnel
S 0 c | e à adhésion obligatoire Garanties exprimées en incluant
souscrit par l’entreprise les remboursements Sécurité sociale *
OBSTETRIQUE
Frais de séjour 175% BR
H Honoraires conventionnés y compris maternité Signataires du CAS (1) 195% BR
Honoraires conventionnés y compris maternité Non Signataires du CAS (1) 175% BR
Honoraires non conventionnés y compris maternité 175% BR
Forfait journalier hospitalier 100 % FR
Forfait actes lourds 100 % FR
Chambre par1iculière en secteur conventionné 100% FR limité à 45 €7jour
Lit d’accompagnant en secteur conventionné 100% FR limité à 45 €jour
Consultations/visites de médecins généralistes - Signataires du CAS (1) 100 % BR
Q} ConsultationçNisites de médecins généralistes - Non Signataires du CAS et en secteur non 100 % BR
convenüonne (1)
Consultationslvisites de médecins spécialistes - Signataires du CAS (1) 195 % BR
ConsultationçNisites de médecins spécialistes - Non Signataires du CAS et en secteur non 175 % BR
convenüonne (1)
Analyses médicales, auxiliaires médicaux 100 % BR
Actes techniques médicaux (petite chirurgie) - Signataires du CAS (1) 150 % BR
Actes techniques médicaux (petite chirurgie) - Non signataires du CAS (1) 130 % BR
Imagerie médicale - Signataires du CAS (1) 100 % BR
Imagerie médicale - Non Signataires du CAS (1) 100 % BR
Or1hopédie et autres prothèses 175 % BR
Prothèses auditives (max 2/an) 450 €/ oreille (avec un
minimum de 100% BR)
Transpor1 accepté 100 % BR
Pharmacie 100 % BR
DENTAIRE (limité à 3 prothèses par an et par bénéficiaire. Au delà,
remboursement a hauteur de 125% BR
Soins dentaires 100 % BR
' Soins dentaires avec dépassements (y compris lnlays/Onlays) 150 % BR
Prothèses dentaires prises en charge par le RO (dents du sourire) 250 % BR
Prothèses dentaires prises en charge par le RO (dents de fonds de bouche) 175 % BR
lnlays cores 150 % BR
Prothèses dentaires non prises en charge par le R0 (2) 150 €
Onhodontæ prise en charge par le R0 250% BR
lmplantologie (2) 500 €
In [5]: from PIL import Image
In [6]: im = Image.open('Downloads/27095236-3554bb50-506d-11e7-9d0d-5b993f230992.jpg')
In [7]: api.SetImage(im)
In [8]: print api.GetUTF8Text().strip()
Santé Bureaux d'études 1/3
Collège Ensemble du personnel
S 0 c | e à adhésion obligatoire Garanties exprimées en incluant
souscrit par l’entreprise les remboursements Sécurité sociale *
OBSTETRIQUE
Frais de séjour 175% BR
H Honoraires conventionnés y compris maternité Signataires du CAS (1) 195% BR
Honoraires conventionnés y compris maternité Non Signataires du CAS (1) 175% BR
Honoraires non conventionnés y compris maternité 175% BR
Forfait journalier hospitalier 100 % FR
Forfait actes lourds 100 % FR
Chambre particulière en secteur conventionné 100% FR limité à 45 €/jour
Lit d’accompagnant en secteur conventionné 100% FR limité à 45 €jour
Consultations/visites de médecins généralistes - Signataires du CAS (1) 100 % BR
Q] ConsultationçNisites de médecins généralistes - Non Signataires du CAS et en secteur non 100 % BR
convenüonne (1)
Consultations/visites de médecins spécialistes - Signataires du CAS (1) 195 % BR
ConsultationçNisites de médecins spécialistes - Non Signataires du CAS et en secteur non 175 % BR
convenüonne (1)
Analyses médicales, auxiliaires médicaux 100 % BR
Actes techniques médicaux (petite chirurgie) - Signataires du CAS (1) 150 % BR
Actes techniques médicaux (petite chirurgie) - Non signataires du CAS (1) 130 % BR
Imagerie médicale - Signataires du CAS (1) 100 % BR
Imagerie médicale - Non Signataires du CAS (1) 100 % BR
Or1hopédie et autres prothèses 175 % BR
Prothèses auditives (max 2/an) 450 €/ oreille (avec un
minimum de 100% BR)
Transpor1 accepté 100 % BR
Pharmacie 100 % BR
DENTAIRE (limité à 3 prothèses par an et par bénéficiaire. Au delà,
remboursement a hauteur de 125% BR
Soins dentaires 100 % BR
" Soins dentaires avec dépassements (y compris lnlays/Onlays) 150 % BR
Prothèses dentaires prises en charge par le RQ (dents du sourire) 250 % BR
Prothèses dentaires prises en charge par le RO (dents de fonds de bouche) 175 % BR
lnlays cores 150 % BR
Prothèses dentaires non prises en charge par le R0 (2) 150 €
Onhodontie prise en charge par le R0 250% BR
lmplantologie (2) 500 €
In [9]: tesserocr.__version__
Out[9]: '2.2.1'
In [10]: print tesserocr.tesseract_version()
tesseract 3.05.01
leptonica-1.74.1
libjpeg 8d (libjpeg-turbo 1.5.1) : libpng 1.6.28 : libtiff 4.0.7 : zlib 1.2.11
from tesserocr.
I tried to reproduce your configuration:
tesserocr.version
'2.2.1'
tesserocr.tesseract_version()
'tesseract 3.05.01\n leptonica-1.74.1\n libjpeg 8d : libpng 1.6.29 : libtiff 4.0.8 : zlib 1.2.8\n'
But I'm still getting the same error :
Python 3.5.3 |Continuum Analytics, Inc.| (default, Mar 6 2017, 12:15:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import tesserocr
api = tesserocr.PyTessBaseAPI(lang='fra')
api.SetImageFile("/path/to/doc/mutuellepdf2.jpg")
print(api.GetUTF8Text().strip())
Traceback (most recent call last):
File "", line 1, in
File "tesserocr.pyx", line 2087, in tesserocr.PyTessBaseAPI.GetUTF8Text (tesserocr.cpp:18324)
File "tesserocr.pyx", line 311, in tesserocr._free_str (tesserocr.cpp:2600)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 74: invalid continuation byte
Do you know what could be the problem ? Maybe tesseract data ? Some env variable to set to force UTF8 ?
Thanks for your help
from tesserocr.
Update: the problem doesn't seems to come from tessdata I just re-download all the training files from github for tesseract 3.XX and it doesn't change anything
from tesserocr.
@sirfz what Python version do you use to test ?
from tesserocr.
@sirfz update: the problem comes from Python 3, when I try to reproduce the error with Python2.7 the example works.
If you want to reproduce it I use Python 3.5.3 inside an Anaconda virtual env.
from tesserocr.
Just tested with Python 3.5.3:
$ ipython3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
Type "copyright", "credits" or "license" for more information.
IPython 5.3.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import tesserocr
In [2]: api = tesserocr.PyTessBaseAPI(lang='fra')
In [3]: api.SetImageFile('Downloads/27095236-3554bb50-506d-11e7-9d0d-5b993f230992.jpg')
In [5]: print(api.GetUTF8Text().strip())
Santé Bureaux d'études 1/3
Collège Ensemble du personnel
S 0 c | e à adhésion obligatoire Garanties exprimées en incluant
souscrit par l’entreprise les remboursements Sécurité sociale *
OBSTETRIQUE
Frais de séjour 175% BR
H Honoraires conventionnés y compris maternité Signataires du CAS (1) 195% BR
Honoraires conventionnés y compris maternité Non Signataires du CAS (1) 175% BR
Honoraires non conventionnés y compris maternité 175% BR
Forfait journalier hospitalier 100 % FR
Forfait actes lourds 100 % FR
Chambre par1iculière en secteur conventionné 100% FR limité à 45 €7jour
Lit d’accompagnant en secteur conventionné 100% FR limité à 45 €jour
Consultations/visites de médecins généralistes - Signataires du CAS (1) 100 % BR
Q} ConsultationçNisites de médecins généralistes - Non Signataires du CAS et en secteur non 100 % BR
convenüonne (1)
Consultationslvisites de médecins spécialistes - Signataires du CAS (1) 195 % BR
ConsultationçNisites de médecins spécialistes - Non Signataires du CAS et en secteur non 175 % BR
convenüonne (1)
Analyses médicales, auxiliaires médicaux 100 % BR
Actes techniques médicaux (petite chirurgie) - Signataires du CAS (1) 150 % BR
Actes techniques médicaux (petite chirurgie) - Non signataires du CAS (1) 130 % BR
Imagerie médicale - Signataires du CAS (1) 100 % BR
Imagerie médicale - Non Signataires du CAS (1) 100 % BR
Or1hopédie et autres prothèses 175 % BR
Prothèses auditives (max 2/an) 450 €/ oreille (avec un
minimum de 100% BR)
Transpor1 accepté 100 % BR
Pharmacie 100 % BR
DENTAIRE (limité à 3 prothèses par an et par bénéficiaire. Au delà,
remboursement a hauteur de 125% BR
Soins dentaires 100 % BR
' Soins dentaires avec dépassements (y compris lnlays/Onlays) 150 % BR
Prothèses dentaires prises en charge par le RO (dents du sourire) 250 % BR
Prothèses dentaires prises en charge par le RO (dents de fonds de bouche) 175 % BR
lnlays cores 150 % BR
Prothèses dentaires non prises en charge par le R0 (2) 150 €
Onhodontæ prise en charge par le R0 250% BR
lmplantologie (2) 500 €
In [8]: sys.version
Out[8]: '3.5.3 (default, Jan 19 2017, 14:11:04) \n[GCC 6.3.0 20170118]'
In [9]: tesserocr.__version__
Out[9]: '2.2.1'
In [10]: print(tesserocr.tesseract_version())
tesseract 3.05.01
leptonica-1.74.1
libjpeg 8d (libjpeg-turbo 1.5.1) : libpng 1.6.28 : libtiff 4.0.7 : zlib 1.2.11
It could possibly be a Cython issue, try upgrading Cython and re-install tesserocr (just install the latest version from pypi, no need to install from the repo as the latest version is already on pypi).
from tesserocr.
pip show cython
Name: Cython
Version: 0.25.2
Looks like it's the latest version of cython
from tesserocr.
To break down what's happening in the _free_str
function, tesseract's GetUTF8Text
method returns a UTF-8 encoded byte string (as documented) which is decoded in Python into a unicode string. The decoding part is handled by Cython (hinted in tesserocr.pyx
's header: #cython: c_string_type=unicode, c_string_encoding=utf-8
). For some reason, in your case, the GetUTF8Text
method is not returning a proper UTF-8 string which I can't really explain to be honest. Try re-installing in a fresh environment, maybe it'll help you pinpoint the problem.
from tesserocr.
Hi!
I'm getting the same error:
Traceback (most recent call last):
File "tess.py", line 2, in
tesserocr.file_to_text('IMG_4094.JPG', lang='rus')
File "tesserocr.pyx", line 2447, in tesserocr.file_to_text
File "tesserocr.pyx", line 311, in tesserocr._free_str
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte
Tested it on python 3.5.2, 3.6.0 and 2.7.13. Error happens only on python 3. On python 2 everything works nicely. Also, tesseract CLI command works:
tesseract IMG_4094.JPG stdout -l rus
РЮ С—НЦ.ПТ45.В.00925
My setup:
sys.version
('3.6.0 (default, Aug 17 2017, 16:44:14) \n'
'[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]')
print(tesserocr.tesseract_version())
tesseract 3.05.01
leptonica-1.74.4
libjpeg 9b : libpng 1.6.32 : libtiff 4.0.8 : zlib 1.2.8
tesserocr.version
'2.2.2'
pip3 show Cython
Name: Cython
Version: 0.27.1
Its really strange, because almost similar images run perfectly without any errors. For example this one goes ok:
CLI output for the last one is КЦ С—НЦ.ЛТ45.В.00925.
Maybe i can help you with some more tests? I ran out of ideas ;(
from tesserocr.
Tested the first image (with rus
and eng
tessdata 3.04.00) and had no issues:
$ python3
Python 3.5.3 (default, Sep 7 2017, 16:23:57)
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tesserocr
>>> api = tesserocr.PyTessBaseAPI(lang='rus')
>>> api.SetImageFile('31202294-aba056ec-a96a-11e7-9887-4067d56f71e5.JPG')
>>> api.GetUTF8Text()
'РЮ С—НЦ.ПТ45.В.00925\n\n'
And here's the result with tessdata 4.00:
$ python3
Python 3.5.3 (default, Sep 7 2017, 16:23:57)
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tesserocr
>>> api = tesserocr.PyTessBaseAPI(lang='rus')
>>> api.SetImageFile('31202294-aba056ec-a96a-11e7-9887-4067d56f71e5.JPG')
>>> api.GetUTF8Text()
'ВЫ С—АШ.ЛТ4А5.В.00925\n\n'
Edit: using tesseract 4.00 (version from tesseract-ocr/tesseract@3847b7d)
from tesserocr.
Tested this in ubuntu vm with exactly the same version of python, tesseract and cython, and everything worked fine there. Also, tried downgrading tesseract to 3.04, but this did not help. I'll try to test this on some other mac, maybe the error is OS specific.
I guess i'll switch to python 2 for now.
from tesserocr.
Maybe it's a locale problem? Not sure how that's configured on Mac but in my case (Ubuntu) it's:
$ echo $LANG
en_US.UTF-8
from tesserocr.
Related Issues (20)
- Failure to build with python:3.11-buster HOT 2
- 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
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.