当前位置: 首页>>代码示例>>Python>>正文


Python QPixmap.fromImage方法代码示例

本文整理汇总了Python中PyQt5.QtGui.QPixmap.fromImage方法的典型用法代码示例。如果您正苦于以下问题:Python QPixmap.fromImage方法的具体用法?Python QPixmap.fromImage怎么用?Python QPixmap.fromImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtGui.QPixmap的用法示例。


在下文中一共展示了QPixmap.fromImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_image

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def update_image(self):
        _, frame = self.vs.read()

        packet = self.processor.getProcessedImage(frame)
        cars_violated = packet['list_of_cars']  # list of cropped images of violated cars
        if len(cars_violated) > 0:
            for c in cars_violated:
                carId = self.database.get_max_car_id() + 1
                car_img = 'car_' + str(carId) + '.png'
                cv2.imwrite('car_images/' + car_img, c)
                self.database.insert_into_cars(car_id=carId, car_img=car_img)

                self.database.insert_into_violations(camera=self.cam_selector.currentText(), car=carId, rule='1',
                                                     time=time.time())

            self.updateLog()

        qimg = self.toQImage(packet['frame'])
        self.live_preview.setPixmap(QPixmap.fromImage(qimg)) 
开发者ID:rahatzamancse,项目名称:Traffic-Rules-Violation-Detection,代码行数:21,代码来源:MainWindow.py

示例2: Mostrar

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def Mostrar (self, label, imagen, nombre, posicionX=650):
        imagen = QPixmap.fromImage(imagen)

        # Escalar imagen a 640x480 si el ancho es mayor a 640 o el alto mayor a 480
        if imagen.width() > 640 or imagen.height() > 480:
            imagen = imagen.scaled(640, 480, Qt.KeepAspectRatio, Qt.SmoothTransformation)

        # Mostrar imagen
        label.setPixmap(imagen)

        # Animación (al finalizar la animación se muestra en la barra de estado el nombre y la extensión de la imagen
        # y se desbloquean los botones).       
        self.animacionMostar = QPropertyAnimation(label, b"geometry")
        self.animacionMostar.finished.connect(lambda: (self.parent.statusBar.showMessage(nombre),
                                                       self.bloquearBotones(True)))
        self.animacionMostar.setDuration(200)
        self.animacionMostar.setStartValue(QRect(posicionX, 0, 640, 480))
        self.animacionMostar.setEndValue(QRect(0, 0, 640, 480))
        self.animacionMostar.start(QAbstractAnimation.DeleteWhenStopped) 
开发者ID:andresnino,项目名称:PyQt5,代码行数:21,代码来源:visorImagenes.py

示例3: setImage

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def setImage(self, image):
        """ Set the scene's current image pixmap to the input QImage or QPixmap.
        Raises a RuntimeError if the input image has type other than QImage or QPixmap.
        :type image: QImage | QPixmap
        """
        if type(image) is QPixmap:
            pixmap = image
        elif type(image) is QImage:
            pixmap = QPixmap.fromImage(image)
        else:
            raise RuntimeError("ImageViewer.setImage: Argument must be a QImage or QPixmap.")
        if self.hasImage():
            self._pixmapHandle.setPixmap(pixmap)
        else:
            self._pixmapHandle = self.scene.addPixmap(pixmap)
        self.setSceneRect(QRectF(pixmap.rect()))  # Set scene size to image size.
        self.updateViewer() 
开发者ID:marcel-goldschen-ohm,项目名称:PyQtImageViewer,代码行数:19,代码来源:QtImageViewer.py

示例4: displayImage

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [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)  # 图片自适应大小

    # 报警系统:是否允许设备响铃 
开发者ID:winterssy,项目名称:face_recognition_py,代码行数:29,代码来源:core.py

示例5: __init__

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        layout = QVBoxLayout(self)
        self.imageLabel = QLabel(self)
        self.imageLabel.setAlignment(Qt.AlignCenter)
        layout.addWidget(self.imageLabel)
        clayout = QHBoxLayout()
        layout.addItem(clayout)
        clayout.addItem(QSpacerItem(
            40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))
        clayout.addWidget(QPushButton('水平翻转', self, clicked=self.doHorFilp))
        clayout.addWidget(QPushButton('垂直翻转', self, clicked=self.doVerFilp))
        clayout.addWidget(QPushButton(
            '顺时针45度', self, clicked=self.doClockwise))
        clayout.addWidget(QPushButton(
            '逆时针45度', self, clicked=self.doAnticlockwise))
        clayout.addItem(QSpacerItem(
            40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))

        # 原始图片
        self.srcImage = QImage('Data/fg.png')
        self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage)) 
开发者ID:PyQt5,项目名称:PyQt,代码行数:24,代码来源:ImageRotate.py

示例6: doClockwise

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def doClockwise(self):
        # 顺时针45度
        image = QImage(self.srcImage.size(),
                       QImage.Format_ARGB32_Premultiplied)
        painter = QPainter()
        painter.begin(image)
        # 以图片中心为原点
        hw = self.srcImage.width() / 2
        hh = self.srcImage.height() / 2
        painter.translate(hw, hh)
        painter.rotate(45)  # 旋转45度
        painter.drawImage(-hw, -hh, self.srcImage)  # 把图片绘制上去
        painter.end()
        self.srcImage = image  # 替换
        self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage))

#         # 下面这个旋转方法针对90度的倍数,否则图片会变大
#         trans = QTransform()
#         trans.rotate(90)
#         self.srcImage = self.srcImage.transformed(
#             trans, Qt.SmoothTransformation)
#         self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage)) 
开发者ID:PyQt5,项目名称:PyQt,代码行数:24,代码来源:ImageRotate.py

示例7: doAnticlockwise

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def doAnticlockwise(self):
        # 逆时针45度
        image = QImage(self.srcImage.size(),
                       QImage.Format_ARGB32_Premultiplied)
        painter = QPainter()
        painter.begin(image)
        # 以图片中心为原点
        hw = self.srcImage.width() / 2
        hh = self.srcImage.height() / 2
        painter.translate(hw, hh)
        painter.rotate(-45)  # 旋转-45度
        painter.drawImage(-hw, -hh, self.srcImage)  # 把图片绘制上去
        painter.end()
        self.srcImage = image  # 替换
        self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage))

#         # 下面这个旋转方法针对90度的倍数,否则图片会变大
#         trans = QTransform()
#         trans.rotate(90)
#         self.srcImage = self.srcImage.transformed(
#             trans, Qt.SmoothTransformation)
#         self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage)) 
开发者ID:PyQt5,项目名称:PyQt,代码行数:24,代码来源:ImageRotate.py

示例8: __init__

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        layout = QVBoxLayout(self)
        self.imgLabel = QLabel(self)
        self.coldSlider = QSlider(Qt.Horizontal, self)
        self.coldSlider.valueChanged.connect(self.doChange)
        self.coldSlider.setRange(0, 255)
        layout.addWidget(self.imgLabel)
        layout.addWidget(self.coldSlider)

        # 加载图片
        self.srcImg = QImage('src.jpg')
        self.imgLabel.setPixmap(QPixmap.fromImage(self.srcImg).scaledToWidth(800, Qt.SmoothTransformation))
        # DLL库
        self.dll = CDLL('Cold.dll')
        print(self.dll) 
开发者ID:PyQt5,项目名称:PyQt,代码行数:18,代码来源:Test.py

示例9: update_image

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def update_image(self):
        _, frame = self.vs.read()

        packet = self.processor.getProcessedImage(frame)
        cars_violated = packet['list_of_cars']  # list of cropped images of violated cars
        if len(cars_violated) > 0:
            for c in cars_violated:
                carId = self.database.getMaxCarId() + 1
                car_img = 'car_' + str(carId) + '.png'
                cv2.imwrite('car_images/' + car_img, c)
                self.database.insertIntoCars(car_id=carId, car_img=car_img)

                self.database.insertIntoViolations(camera=self.cam_selector.currentText(), car=carId, rule='1',
                                                   time=time.time())

            self.updateLog()

        qimg = self.toQImage(packet['frame'])
        self.live_preview.setPixmap(QPixmap.fromImage(qimg)) 
开发者ID:sakibreza,项目名称:Traffic-Rules-Violation-Detection-System,代码行数:21,代码来源:MainWindow.py

示例10: displayImage

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def displayImage(self, fileNameId):
        '''
        Display an image in the GUI
        :param fileNameId: The image ID
        '''
        image = QImage(self.imgs[fileNameId])
        if image.isNull():
            QMessageBox.information(self, "Image Viewer",
                    "Cannot load %s." % self.imgs[fileNameId])
            return
        self.imageLabel.setPixmap(QPixmap.fromImage(image))
        self.scaleImage(1)
        #self.imageLabel.adjustSize()
        self.currImg = fileNameId
        self.displayPrevAct.setEnabled(self.currImg != 0)
        self.displayNextAct.setEnabled(self.currImg + 1 != len(self.imgs)) 
开发者ID:Kawaboongawa,项目名称:Zolver,代码行数:18,代码来源:Viewer.py

示例11: np2Qt

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def np2Qt(image):
    """Convert numpy array to QPixmap.
    """
    height, width, bytesPerComponent = image.shape
    bytesPerLine = 4 * width

    if bytesPerComponent == 3:
        image = cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
    qimg = QImage(image.data, width, height,
                  bytesPerLine, QImage.Format_ARGB32)
    return QPixmap.fromImage(qimg) 
开发者ID:xsyann,项目名称:detection,代码行数:13,代码来源:common.py

示例12: toqpixmap

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def toqpixmap(im):
    # # This doesn't work. For now using a dumb approach.
    # im_data = _toqclass_helper(im)
    # result = QPixmap(im_data['im'].size[0], im_data['im'].size[1])
    # result.loadFromData(im_data['data'])
    # Fix some strange bug that causes
    if im.mode == 'RGB':
        im = im.convert('RGBA')

    qimage = toqimage(im)
    return QPixmap.fromImage(qimage) 
开发者ID:tp4a,项目名称:teleport,代码行数:13,代码来源:ImageQt.py

示例13: toqpixmap

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def toqpixmap(im):
    # # This doesn't work. For now using a dumb approach.
    # im_data = _toqclass_helper(im)
    # result = QPixmap(im_data['im'].size[0], im_data['im'].size[1])
    # result.loadFromData(im_data['data'])
    # Fix some strange bug that causes
    if im.mode == "RGB":
        im = im.convert("RGBA")

    qimage = toqimage(im)
    return QPixmap.fromImage(qimage) 
开发者ID:tp4a,项目名称:teleport,代码行数:13,代码来源:ImageQt.py

示例14: resetPixmap

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def resetPixmap(self, image):

        self.frame_item.setPixmap(QPixmap.fromImage(image)) 
开发者ID:fanghon,项目名称:lpr,代码行数:5,代码来源:HyperLprGUI.py

示例15: inverted_icon

# 需要导入模块: from PyQt5.QtGui import QPixmap [as 别名]
# 或者: from PyQt5.QtGui.QPixmap import fromImage [as 别名]
def inverted_icon(icon, width=32, height=32, as_image=False):
    pixmap = icon.pixmap(width, height)
    image = pixmap.toImage()
    image.invertPixels()
    if as_image:
        return image
    new_icon = QIcon(QPixmap.fromImage(image))
    return new_icon 
开发者ID:krassowski,项目名称:Anki-Night-Mode,代码行数:10,代码来源:icons.py


注:本文中的PyQt5.QtGui.QPixmap.fromImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。