Rya*_*ack 5 python opencv image python-imaging-library google-cloud-dataflow
我正在努力从 Python 类的实例中正确打开 TIFF 图像io.BufferedReader。我使用下面的库从 GCS 路径下载图像,但我似乎无法使用传统工具打开图像。
# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')
from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"
img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"
Run Code Online (Sandbox Code Playgroud)
除了 PIL 之外,我对其他库持开放态度。
更新
以下也失败:
img = Image.open(file)
Run Code Online (Sandbox Code Playgroud)
它失败并出现 IOError,指出tempfile.tif: Cannot read TIFF header.
确保将两者包装在 ContextManager 中,以便它们都能正确关闭。
with beam.io.gcp.gcsio.GcsIO().open(file_path, 'r') as file, Image.open(io.BytesIO(file.read())) as multi_page_tiff:
do_stuff()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4798 次 |
| 最近记录: |