IOError: cannot identify image file when loading images from pdf files

748
June 19, 2017, at 00:47 AM

I am trying to read scanned images from a pdf using wand and display it using PIL. But I get some error. First page of the pdf file works perfectly but the second page shows this error.

Code

from wand.image import Image
from wand.display import display
from PIL import Image as PI
import pyocr
import pyocr.builders
import io
import numpy as np
import cStringIO
tool = pyocr.get_available_tools()[0]
lang = tool.get_available_languages()[1]
req_image = []
final_text = []
image_pdf = Image(filename="DEEP_PLAST_20.700.pdf", resolution=200)
image_jpeg = image_pdf.convert('jpeg')
img_page = Image(image=image_jpeg.sequence[1])
img_buffer = np.asarray(bytearray(img_page.make_blob()), dtype=np.uint8)
print(img_buffer)
# im = PI.fromarray(img_buffer)
im = PI.open(cStringIO.StringIO(img_buffer))

I get this error.

Traceback (most recent call last):
  File "ocr.py", line 43, in <module>
    im = PI.open(cStringIO.StringIO(img_buffer))
  File "/home/sahil/anaconda2/lib/python2.7/site-packages/PIL/Image.py", line 2452, in open
    % (filename if filename else fp))
IOError: cannot identify image file <cStringIO.StringI object at 0x7fc4a8f168b0>

I don't why the code fails on the second page of the pdf whereas it works for the first one.

Any help would be appreciated!

Rent Charter Buses Company
READ ALSO
How to pip install forex python

How to pip install forex python

I am attempting to install forex-pythonI have attempted to find a meaningful answer to this question everywhere, however my search has been in vain

631
Cannot build LSTM layers in Keras

Cannot build LSTM layers in Keras

I am trying to develop Keras LSTM codeI have input data which is represent audio features, it is like that

455
How to get Sha256 checksum in browser and send it along with file upload to the server in a POST request

How to get Sha256 checksum in browser and send it along with file upload to the server in a POST request

I need to make a python django page where it's possible to upload a file (under 10KB) that would show the Sha256 checksum of it and show how many times this file was uploaded beforeThere's also a subgoal of making the browser itself calc Sha256

392