3

The below code is what i am using to read mrz data from a passport, and it works absolutely fine when i run it on my local computer, but when i try to execute it on my server (Windows AWS server) it throws an error. Can you please help what's this error and how to resolve it.

from PIL import Image
import sys
from passporteye import read_mrz
import pytesseract

mrz = read_mrz("C:/docs/IMG/PASSPORT/abc.png")

Error :

Traceback (most recent call last):
  File "C:/qfc_apps/edocs/PY/PASSPORT/passport.py", line 64, in <module>
    passport()
  File "C:/qfc_apps/edocs/PY/PASSPORT/passport.py", line 19, in passport
    mrz = read_mrz("C:/docs/IMG/PASSPORT/abc.png")
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\mrz\image.py", line 337, in read_mrz
    mrz = p.result
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\mrz\image.py", line 325, in result
    return self['mrz_final']
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\util\pipeline.py", line 102, in __getitem__
    self._compute(key)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\util\pipeline.py", line 109, in _compute
    self._compute(d)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\util\pipeline.py", line 109, in _compute
    self._compute(d)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\util\pipeline.py", line 109, in _compute
    self._compute(d)
  [Previous line repeated 1 more times]
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\util\pipeline.py", line 111, in _compute
    results = self.components[cname](*inputs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\mrz\image.py", line 52, in __call__
    return self._imread(self.file)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\passporteye\mrz\image.py", line 37, in _imread
    img = skimage_io.imread(file, as_gray=self.as_gray, plugin='imageio')
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\skimage\io\_io.py", line 61, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core\functions.py", line 221, in imread
    reader = read(uri, format, "i", **kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\imageio\core\functions.py", line 139, in get_reader
    "Could not find a format to read the specified file " "in mode %r" % mode
ValueError: Could not find a format to read the specified file in mode 'i'
gaurav2141
  • 130
  • 8

1 Answers1

3

Figured out the solution after hours of research so posting my solution for others who might face a similar solution.

I still couldnt figure out what was the problem with the above code but i managed a way out.

Documentation of passporteye mentions that either we pass the path of the image or a byte stream containing image data. As path was not working for me so i opted for the second method.

Using the below code solves our problem :-

image = cv2.imread("path of image")
import PIL.Image as Image
 import io
 pil_im = Image.fromarray(image)
 b = io.BytesIO()
 pil_im.save(b, 'jpeg')
 im_bytes = b.getvalue()

 mrz = read_mrz(im_bytes)
gaurav2141
  • 130
  • 8