本文整理匯總了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))
示例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)
示例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()
示例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) # 圖片自適應大小
# 報警係統:是否允許設備響鈴
示例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))
示例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))
示例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))
示例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)
示例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))
示例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))
示例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)
示例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)
示例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)
示例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))
示例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