How to reduce wand memory usage?

前端 未结 4 1666
南方客
南方客 2021-01-13 09:36

I am using wand and pytesseract to get the text of pdfs uploaded to a django website like so:

image_pdf = Image(blob=read_pdf_file, resolution=300)
image_png         


        
4条回答
  •  情深已故
    2021-01-13 09:38

    The code from @emcconville works, and my temp folder is not filling up with magick-* files anymore

    I needed to Import ctypes and not cstyles

    I also got the error mentioned by @kerthik

    solved it by saving the image and loading it again, it is properly also possible to save it to memory

    from PIL import Image as PILImage
    
    ...
    context.save(filename="temp.jpg")
    text = pytesseract.image_to_string(PILImage.open("temp.jpg"))`
    

    EDIT I found the in memory conversion on How to convert wand.image.Image to PIL.Image?

    img_buffer = np.asarray(bytearray(context.make_blob(format='png')),dtype='uint8')
    bytesio = io.BytesIO(img_buffer)
    text = ytesseract.image_to_string(PILImage.open(bytesio),lang="dan")
    

提交回复
热议问题