Python PyQt5.QtGui.QImage.Format_RGBA8888() Examples
The following are 6
code examples of PyQt5.QtGui.QImage.Format_RGBA8888().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtGui.QImage
, or try the search function
.
Example #1
Source File: MainWindow.py From Traffic-Rules-Violation-Detection with GNU General Public License v3.0 | 7 votes |
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
Example #2
Source File: core.py From face_recognition_py with GNU General Public License v3.0 | 6 votes |
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) # 图片自适应大小 # 报警系统:是否允许设备响铃
Example #3
Source File: imutils.py From SickZil-Machine with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #4
Source File: gui_utilities.py From CvStudio with MIT License | 5 votes |
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)
Example #5
Source File: dataRecord.py From face_recognition_py with GNU General Public License v3.0 | 5 votes |
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) # 初始化数据库
Example #6
Source File: MainWindow.py From Traffic-Rules-Violation-Detection-System with GNU General Public License v3.0 | 5 votes |
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