Giter Club home page Giter Club logo

Comments (22)

msaada avatar msaada commented on May 12, 2024 1

@sirfz Yes it solved the problem thanks for your help ;)

from tesserocr.

Dront avatar Dront commented on May 12, 2024 1

Both ubuntu and mac use en_US.UTF-8. It's magic.

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

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.

msaada avatar msaada commented on May 12, 2024

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 :
20170509_182040

cython.version
'0.25.2'

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

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.

msaada avatar msaada commented on May 12, 2024

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.

sirfz avatar sirfz commented on May 12, 2024

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.

msaada avatar msaada commented on May 12, 2024

It seems that upgrading only tesserocr solved the problem as I'm not able to reproduce the error.

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

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.

msaada avatar msaada commented on May 12, 2024

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

mutuellepdf2

Thanks for your help

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

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 lentreprise 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é à 457jour
Lit daccompagnant en secteur conventionné 100% FR limité à 45jour
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) 150Onhodontæ prise en charge par le R0 250% BR

lmplantologie (2) 500In [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 lentreprise 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 daccompagnant en secteur conventionné 100% FR limité à 45jour
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) 150Onhodontie prise en charge par le R0 250% BR

lmplantologie (2) 500In [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.

msaada avatar msaada commented on May 12, 2024

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.

msaada avatar msaada commented on May 12, 2024

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.

msaada avatar msaada commented on May 12, 2024

@sirfz what Python version do you use to test ?

from tesserocr.

msaada avatar msaada commented on May 12, 2024

@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.

sirfz avatar sirfz commented on May 12, 2024

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.

msaada avatar msaada commented on May 12, 2024

pip show cython
Name: Cython
Version: 0.25.2

Looks like it's the latest version of cython

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

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.

Dront avatar Dront commented on May 12, 2024

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

Image with error:
img_4094

Its really strange, because almost similar images run perfectly without any errors. For example this one goes ok:
img_4096
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.

sirfz avatar sirfz commented on May 12, 2024

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.

Dront avatar Dront commented on May 12, 2024

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.

sirfz avatar sirfz commented on May 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.