How do I install OpenJPEG on Windows and use it with Pillow?

扶醉桌前 提交于 2019-12-12 14:00:22

问题


I would like to use the Python Pillow library to save 16 bit gray scale arrays in the jp2 ("JPEG 2000") format.

I have hit a brick wall in trying to install the required library OpenJPEG on my Windows machine. The documentation is not very clear... but I assumed that I needed to download the Win64 binaries and simply put them on my path ( which I did).

That done, I am still getting the following error when using Pillow 4.0.0 in Anaconda 4.3.0 on Windows.

IOError: encoder jpeg2k not available

Anyone out there successfully used Pillow to write and read JPEG 2000 files, I would sure appreciate some tips.

Edit:

Here is the code that fails:

import PIL
import numpy as np

arr = np.ones(dtype=np.uint16, shape=(100, 100))
im = PIL.Image.fromarray(arr)
im.save('arr.jp2')

回答1:


I've just installed Pillow with an installer from here. I chose Pillow-4.0.0.win-amd64-py3.5.exe. During install it found conda's python and properly chose where to install (it installed to a root environment).

Code to test it works:

from PIL import Image
import numpy as np
arr = np.ones(dtype=np.uint16, shape=(100,100))
im = Image.fromarray(arr)
im.save('test.jp2') 

Note, that saved file has 8 bpp.




回答2:


Anaconda build Python using different version of the microsoft visual studio tools.

Each version of those tools has its own runtime, which is incompatible with other versions.

The Pillow library used compiled shared libraries. You will need to compile OpenJPEG with exactly the same version of the ms visual studio tools that was used to build Python and Pillow.




回答3:


For general reference.

The Windows equivalent to 'nix .so files have the extension .dll (sic - "Windows Binaries" - dynamic linked library); and yes, the file has to reside somewhere in the system PATH.

Being in the PATH allows Windows to find the file, but that's not enough. Windows has to be told what can be done with it; that it's a shareable library. That's done by:

1) Open a DOS Command Prompt in the (sub)directory where the binary is located; e.g. C:\LIBS

2) Run the command "regsvr32 filename.dll". This registers the .dll as a shared file (in Windows Registry), so that Windows knows how to load it into memory and let user applications access it.

You can actually run regsvr32 from any directory (it's a System file & should be somewhere in the C:\Windows\system32 directory; but it's more convenient to run in the same directory as the .dll because otherwise you have to prepend filename.dll with the entire directory tree from C:\ to where ever the file is located.

You can run "regsvr32" with no target filename to get a popup list of command-line switches which can be used.



来源:https://stackoverflow.com/questions/42184995/how-do-i-install-openjpeg-on-windows-and-use-it-with-pillow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!