本文整理汇总了Python中PyQt5.QtGui.QImage.Format_RGBA8888方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.Format_RGBA8888方法的具体用法?Python QImage.Format_RGBA8888怎么用?Python QImage.Format_RGBA8888使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QImage
的用法示例。
在下文中一共展示了QImage.Format_RGBA8888方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: displayImage
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGBA8888 [as 别名]
def displayImage(self, img, qlabel):
# BGR -> RGB
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# default:The image is stored using 8-bit indexes into a colormap, for example:a gray image
qformat = QImage.Format_Indexed8
if len(img.shape) == 3: # rows[0], cols[1], channels[2]
if img.shape[2] == 4:
# The image is stored using a 32-bit byte-ordered RGBA format (8-8-8-8)
# A: alpha channel,不透明度参数。如果一个像素的alpha通道数值为0%,那它就是完全透明的
qformat = QImage.Format_RGBA8888
else:
qformat = QImage.Format_RGB888
# img.shape[1]:图像宽度width,img.shape[0]:图像高度height,img.shape[2]:图像通道数
# QImage.__init__ (self, bytes data, int width, int height, int bytesPerLine, Format format)
# 从内存缓冲流获取img数据构造QImage类
# img.strides[0]:每行的字节数(width*3),rgb为3,rgba为4
# strides[0]为最外层(即一个二维数组所占的字节长度),strides[1]为次外层(即一维数组所占字节长度),strides[2]为最内层(即一个元素所占字节长度)
# 从里往外看,strides[2]为1个字节长度(uint8),strides[1]为3*1个字节长度(3即rgb 3个通道)
# strides[0]为width*3个字节长度,width代表一行有几个像素
outImage = QImage(img, img.shape[1], img.shape[0], img.strides[0], qformat)
qlabel.setPixmap(QPixmap.fromImage(outImage))
qlabel.setScaledContents(True) # 图片自适应大小
# 报警系统:是否允许设备响铃
示例2: toQImage
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGBA8888 [as 别名]
def toQImage(self, raw_img):
from numpy import copy
img = copy(raw_img)
qformat = QImage.Format_Indexed8
if len(img.shape) == 3:
if img.shape[2] == 4:
qformat = QImage.Format_RGBA8888
else:
qformat = QImage.Format_RGB888
outImg = QImage(img.tobytes(), img.shape[1], img.shape[0], img.strides[0], qformat)
outImg = outImg.rgbSwapped()
return outImg
示例3: np_bgra2qimg
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGBA8888 [as 别名]
def np_bgra2qimg(cvimg):
''' convert cv2 bgr image -> rgb qimg '''
h,w,c = cvimg.shape
byte_per_line = w * c #cvimg.step() #* step # NOTE:when image format problem..
return QImage(cvimg.data, w,h, byte_per_line,
QImage.Format_RGBA8888).rgbSwapped()
示例4: color_icon2gray_icon
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGBA8888 [as 别名]
def color_icon2gray_icon(cls, icon: QIcon):
# TODO: implement for RGB icons
pixmap = icon.pixmap(icon.availableSizes()[0])
img_array = cls.Qpixmap2array(pixmap)
*_, alpha = cv2.split(img_array)
gray_layer = cv2.cvtColor(img_array, cv2.COLOR_BGR2GRAY)
gray_img = cv2.merge((gray_layer, gray_layer, gray_layer, alpha))
height, width, channel = gray_img.shape
bytesPerLine = 4 * width
qImg = QImage(gray_img.data, width, height, bytesPerLine, QImage.Format_RGBA8888)
pixmap = QtGui.QPixmap.fromImage(qImg)
return QIcon(pixmap)
示例5: displayImage
# 需要导入模块: from PyQt5.QtGui import QImage [as 别名]
# 或者: from PyQt5.QtGui.QImage import Format_RGBA8888 [as 别名]
def displayImage(self, img):
# BGR -> RGB
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# default:The image is stored using 8-bit indexes into a colormap, for example:a gray image
qformat = QImage.Format_Indexed8
if len(img.shape) == 3: # rows[0], cols[1], channels[2]
if img.shape[2] == 4:
# The image is stored using a 32-bit byte-ordered RGBA format (8-8-8-8)
# A: alpha channel,不透明度参数。如果一个像素的alpha通道数值为0%,那它就是完全透明的
qformat = QImage.Format_RGBA8888
else:
qformat = QImage.Format_RGB888
# img.shape[1]:图像宽度width,img.shape[0]:图像高度height,img.shape[2]:图像通道数
# QImage.__init__ (self, bytes data, int width, int height, int bytesPerLine, Format format)
# 从内存缓冲流获取img数据构造QImage类
# img.strides[0]:每行的字节数(width*3),rgb为3,rgba为4
# strides[0]为最外层(即一个二维数组所占的字节长度),strides[1]为次外层(即一维数组所占字节长度),strides[2]为最内层(即一个元素所占字节长度)
# 从里往外看,strides[2]为1个字节长度(uint8),strides[1]为3*1个字节长度(3即rgb 3个通道)
# strides[0]为width*3个字节长度,width代表一行有几个像素
outImage = QImage(img, img.shape[1], img.shape[0], img.strides[0], qformat)
self.faceDetectCaptureLabel.setPixmap(QPixmap.fromImage(outImage))
self.faceDetectCaptureLabel.setScaledContents(True)
# 初始化数据库