Python:TIFFReadDirectory警告:带有标签的未知字段

问题描述 投票:0回答:1

问题我可以使用Image()模块来载入图片。 This是我如何安装kivy,以便可以查看TIFF文件。但是现在每次我加载TIFF图像时,都会接连收到几个弹出警告,从而中断程序。

TIFFReadDirectory warning:
unknown field with tag 18246 (0x4746)
TIFFReadDirectory warning:
unknown field with tag 18249 (0x4749)
TIFFReadDirectory warning:
unknown field with tag 20752 (0x5110)
TIFFReadDirectory warning:
unknown field with tag 20753 (0x5111)
TIFFReadDirectory warning:
unknown field with tag 20754 (0x5112)
TIFFReadDirectory warning:
unknown field with tag 40092 (0x9c9c)
TIFFReadDirectory warning:
unknown field with tag 40093 (0x9c9d)
TIFFReadDirectory warning:
unknown field with tag 40094 (0x9c9e)

为了澄清,这些警告均未出现在python日志中。这些是在程序显示TIFF文件之前出现的所有单独的警告框。我听说一个名为libtiff的库往往会导致此问题。

code

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.uix.image import Image

class ContainerBox(BoxLayout):
    def __init__(self, **kwargs):
        super(ContainerBox, self).__init__(**kwargs)
        self.orientation = 'vertical'
        self.picture = Image(allow_stretch=True, source='..\pics\snorlax.tif')
        Clock.schedule_once(lambda dt: self.add_widget(self.picture), timeout=0.1)


class SimpleImage(App):
    def build(self):
        return ContainerBox()

if __name__ == '__main__':
    SimpleImage().run()

技术细节

  • 可以下载图像here
  • 我已经修改了此文件的exif数据。我可能在文件中添加了两个非标准标签。但是我对jpg文件和png文件做了同样的事情。那些还没有引起像这样的烦人的弹出窗口。
  • 我正在使用Kivy 1.11.1版
  • 根据Anaconda,虚拟环境正在运行Python 3.5.6
  • 我正在Windows 7上通过PyCharm运行它
  • 这些是python日志中的详细信息:
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.1.12
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.1.22
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "C:\Users\H\venvs\env1\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\H\venvs\env1\Scripts\python.exe"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] [Loader      ] using a thread pool of 2 workers
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'4.0.0 - Build 9.18.10.3204'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) HD Graphics 4600'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 0
[INFO   ] [GL          ] Shading version <b'4.00 - Build 9.18.10.3204'>
[INFO   ] [GL          ] Texture max size <8192>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider

我对你的问题是否可以禁止这些警告?我认为它们是由某些图书馆猕猴桃正在调用生成的。它甚至可能是我无法编辑的预编译代码。我花了很长时间与Kivy建立一个复杂的用户界面。我真的不想丢掉所有这些工作。但我可能愿意将其迁移到C ++,从理论上讲我可以控制更多代码。那是必要的甚至是可能的吗?

python python-3.x kivy tiff libtiff
1个回答
0
投票

在脚本的开头,我添加了

import ctypes

libbytiff = ctypes.CDLL("libtiff-5.dll")
libbytiff.TIFFSetWarningHandler(0)

警告已停止。

© www.soinside.com 2019 - 2024. All rights reserved.