在QLabel中渲染WSQ图像的最佳方法是什么

时间:2014-01-14 16:49:06

标签: python image-processing qpixmap pyqt5

我试图在PyQt5中的QLabel中渲染WSQ图像。 WSQ映像位于xml文件中,该文件位于zip文件中。这是我的方法:

import zipfile
import xml.etree.cElementTree as ET
import base64.b64decode as b64decode
from PyQt5 import QtGui, QtWidgets
...
try:
    with zipfile.ZipFile(zfilename) as src_zip:
        root = ET.fromstring(src_zip.open(xmlfilename).read())
except zipfile.BadZipFile as e:
    root = None
finger_prints = []
if root:
    for data in root.findall('.//Demographics/FingerData'):
        finger_prints.append(b64decode(data.find('FingerprintImage').text))
...
finger_data = finger_prints.pop()
pixmap = QtGui.QPixmap()
pixmap.loadFromData(finger_data, 'WSQ') # freezes
QtWidgets.QLabel().setPixmap(pixmap)

第二行但最后一行导致程序冻结/挂起,但如果我这样做:

with file('/tmp/finger_print.wsq', 'wb') as f:
    f.write(finger_data)

我能够在WSQ查看器中查看图像。我知道Qt有不同图像格式的插件,是否有我缺少的图像插件?

提前感谢您的帮助。

,亚伯拉罕。

1 个答案:

答案 0 :(得分:1)

image formats Qt默认支持:

 Format  Description                            Qt's support
 BMP     Windows Bitmap                         Read/write
 GIF     Graphic Interchange Format (optional)  Read
 JPG     Joint Photographic Experts Group       Read/write
 JPEG    Joint Photographic Experts Group       Read/write
 PNG     Portable Network Graphics              Read/write
 PBM     Portable Bitmap                        Read
 PGM     Portable Graymap                       Read
 PPM     Portable Pixmap                        Read/write
 XBM     X11 Bitmap                             Read/write
 XPM     X11 Pixmap                             Read/write

所以你要么必须写custom Qt image plugin,要么以某种方式将图像数据转换为Qt理解的格式之一。