Python PyQt5.QtGui.QPixmap.fromImage() Examples
The following are 30
code examples of PyQt5.QtGui.QPixmap.fromImage().
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.QPixmap
, or try the search function
.
Example #1
Source File: visorImagenes.py From PyQt5 with MIT License | 7 votes |
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)
Example #2
Source File: Viewer.py From Zolver with MIT License | 6 votes |
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))
Example #3
Source File: MainWindow.py From Traffic-Rules-Violation-Detection with GNU General Public License v3.0 | 6 votes |
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))
Example #4
Source File: Test.py From PyQt with GNU General Public License v3.0 | 6 votes |
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)
Example #5
Source File: ImageRotate.py From PyQt with GNU General Public License v3.0 | 6 votes |
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))
Example #6
Source File: ImageRotate.py From PyQt with GNU General Public License v3.0 | 6 votes |
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))
Example #7
Source File: ImageRotate.py From PyQt with GNU General Public License v3.0 | 6 votes |
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))
Example #8
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 #9
Source File: ComboBoxDelegate.py From urh with GNU General Public License v3.0 | 6 votes |
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex): editor = QComboBox(parent) if sys.platform == "win32": # Ensure text entries are visible with windows combo boxes editor.setMinimumHeight(self.sizeHint(option, index).height() + 10) editor.addItems(self.items) if self.is_editable: editor.setEditable(True) editor.setInsertPolicy(QComboBox.NoInsert) if self.current_edit_text: editor.setEditText(self.current_edit_text) if self.colors: img = QImage(16, 16, QImage.Format_RGB32) painter = QPainter(img) painter.fillRect(img.rect(), Qt.black) rect = img.rect().adjusted(1, 1, -1, -1) for i, item in enumerate(self.items): color = self.colors[i] painter.fillRect(rect, QColor(color.red(), color.green(), color.blue(), 255)) editor.setItemData(i, QPixmap.fromImage(img), Qt.DecorationRole) del painter editor.currentIndexChanged.connect(self.currentIndexChanged) editor.editTextChanged.connect(self.on_edit_text_changed) return editor
Example #10
Source File: QtImageViewer.py From PyQtImageViewer with MIT License | 6 votes |
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()
Example #11
Source File: MainWindow.py From Traffic-Rules-Violation-Detection-System with GNU General Public License v3.0 | 6 votes |
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))
Example #12
Source File: qrcode.py From artisan with GNU General Public License v3.0 | 5 votes |
def pixmap(self): return QPixmap.fromImage(self._image)
Example #13
Source File: Ui_MakupGUI.py From AIMakeup with Apache License 2.0 | 5 votes |
def _set_img(self): ''' 显示pixmap ''' self.label.setPixmap(QPixmap.fromImage(self._cv2qimg(self.temp_bgr)))
Example #14
Source File: VideoMainWindow.py From Insect_Identification with Apache License 2.0 | 5 votes |
def convertFrame(self): """ converts frame to format suitable for QtGui """ try: height, width = self.currentFrame.shape[:2] img = QImage(self.currentFrame, width, height, QImage.Format_RGB888) img = QPixmap.fromImage(img) self.previousFrame = self.currentFrame return img except: return None
Example #15
Source File: VideoMainWindow.py From Insect_Identification with Apache License 2.0 | 5 votes |
def convertSpecifiedFrame(frame): """ converts frame to format suitable for QtGui """ try: height, width = frame.shape[:2] img = QImage(frame, width, height, QImage.Format_RGB888) img = QPixmap.fromImage(img) return img except: return None
Example #16
Source File: Test.py From PyQt with GNU General Public License v3.0 | 5 votes |
def doChange(self, value): t = time() img = self.srcImg.copy() # 复制一份 # For PyQt5 self.dll.cold(sip.unwrapinstance(img), value) # For PySide2 # self.dll.cold(shiboken2.getCppPointer(img)[0], value) self.imgLabel.setPixmap(QPixmap.fromImage(img).scaledToWidth(800, Qt.SmoothTransformation)) print('use time:', time() - t)
Example #17
Source File: mapper.py From guiscrcpy with GNU General Public License v3.0 | 5 votes |
def mouseReleaseEvent(self, event): if event.button == Qt.LeftButton: # self.drawing = False self.label.setPixmap(QPixmap.fromImage(self.image))
Example #18
Source File: mapper.py From guiscrcpy with GNU General Public License v3.0 | 5 votes |
def mouseMoveEvent(self, event): if event.buttons() & Qt.LeftButton: # painter.setPen(QPen(self.brushColor, # self.brushSize, Qt.SolidLine, Qt.RoundCap,Qt.RoundJoin)) # painter.drawLine( # self.label.mapFromParent(event.pos()),self.last_found_point) self.last_found_point = self.label.mapFromParent( event.pos()) # this is working fine now print(self.last_found_point, "MOVE") fixed_pos[0] = int(event.pos().x()) fixed_pos[1] = int(event.pos().y()) # self.label.setPixmap(QPixmap.fromImage(self.image))
Example #19
Source File: mapper.py From guiscrcpy with GNU General Public License v3.0 | 5 votes |
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.last_found_point = event.pos() fixed_pos[0] = int(event.pos().x()) fixed_pos[1] = int(event.pos().y()) print(self.last_found_point, "LAST") self.last_found_point = self.label.mapFromParent( event.pos()) # this is working fine now # self.label.setPixmap(QPixmap.fromImage(self.image))
Example #20
Source File: VideoMainWindow.py From Insect_Identification with Apache License 2.0 | 5 votes |
def drawpic(self,FFRRAAMM): """ converts frame to format suitable for QtGui """ try: height, width = FFRRAAMM.shape[:2] img = QImage(FFRRAAMM, width, height, QImage.Format_RGB888) img = QPixmap.fromImage(img) return img except: return None
Example #21
Source File: ImageQt.py From FODI with GNU General Public License v3.0 | 5 votes |
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)
Example #22
Source File: ImageQt.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
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)
Example #23
Source File: OptionsDialog.py From urh with GNU General Public License v3.0 | 5 votes |
def show_available_colormaps(self): height = 50 selected = colormaps.read_selected_colormap_name_from_settings() for colormap_name in sorted(colormaps.maps.keys()): image = Spectrogram.create_colormap_image(colormap_name, height=height) rb = QRadioButton(colormap_name) rb.setObjectName(colormap_name) rb.setChecked(colormap_name == selected) rb.setIcon(QIcon(QPixmap.fromImage(image))) rb.setIconSize(QSize(256, height)) self.ui.scrollAreaWidgetSpectrogramColormapContents.layout().addWidget(rb)
Example #24
Source File: SpectrumDialogController.py From urh with GNU General Public License v3.0 | 5 votes |
def __update_spectrogram(self): spectrogram = Spectrogram(self.device.data) spectrogram.data_min = -80 spectrogram.data_max = 10 scene = self.ui.graphicsViewSpectrogram.scene() pixmap = QPixmap.fromImage(spectrogram.create_spectrogram_image(transpose=True)) pixmap_item = scene.addPixmap(pixmap) pixmap_item.moveBy(0, self.spectrogram_y_pos) self.spectrogram_y_pos += pixmap.height() if self.spectrogram_y_pos >= scene.sceneRect().height(): scene.setSceneRect(0, 0, Spectrogram.DEFAULT_FFT_WINDOW_SIZE, self.spectrogram_y_pos) self.ui.graphicsViewSpectrogram.ensureVisible(pixmap_item)
Example #25
Source File: ImageQt.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
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)
Example #26
Source File: DroneVisionGUI.py From pyparrot with MIT License | 5 votes |
def run(self): #print("user window draw thread being called") while (self.drone_vision.vision_running): img = self.user_draw_function() if(img is not None): if (not img.isNull()): self.drone_vision.vlc_gui.userWindow.setPixmap(QPixmap.fromImage(img)) # put the thread back to sleep for fps # sleeping shorter to ensure we stay caught up on frames time.sleep(1.0 / (3.0 * self.drone_vision.fps)) # exit when the vision thread ends print("exiting user window draw thread") self.terminate()
Example #27
Source File: SpectrogramSceneManager.py From urh with GNU General Public License v3.0 | 5 votes |
def show_full_scene(self): for item in self.scene.items(): if isinstance(item, QGraphicsPixmapItem): self.scene.removeItem(item) x_pos = 0 for image in self.spectrogram.create_image_segments(): item = self.scene.addPixmap(QPixmap.fromImage(image)) item.setPos(x_pos, 0) x_pos += image.width() QApplication.instance().processEvents() # Estimated time_bins from update_scene_rect may be too many for small signals so we update the scene rect # after we know how wide the spectrogram actually is self.scene.setSceneRect(0, 0, x_pos, self.spectrogram.freq_bins)
Example #28
Source File: live_spectrogram.py From urh with GNU General Public License v3.0 | 5 votes |
def go(): global graphic_view, status_label data_parent, data_child = Pipe(duplex=False) receiver = Process(target=generate_data, args=(data_child,)) receiver.daemon = True receiver.start() scene = QGraphicsScene() graphic_view.setScene(scene) scene.setSceneRect(0, 0, 1024, 1024) x_pos = 0 y_pos = 0 t = time.time() while True: speed = time.time() data = data_parent.recv() spectrogram = Spectrogram(data) pixmap = QPixmap.fromImage(spectrogram.create_spectrogram_image(transpose=True)) scene.setSceneRect(scene.sceneRect().adjusted(0, 0, 0, pixmap.height())) item = scene.addPixmap(pixmap) item.setPos(x_pos, y_pos) y_pos += pixmap.height() graphic_view.fitInView(scene.sceneRect()) status_label.setText("Height: {0:.0f} // Speed: {1:.2f} // Total Time: {2:.2f}".format(scene.sceneRect().height(), 1/(time.time()-speed), time.time()-t)) QApplication.instance().processEvents()
Example #29
Source File: card.py From CvStudio with MIT License | 5 votes |
def source(self, value): self._video_source = value qimage = GUIUtilities.array_to_qimage(self._video_source) pixmap = QPixmap.fromImage(qimage) pixmap = pixmap.scaledToHeight(120, mode=QtCore.Qt.SmoothTransformation) # pixmap=pixmap.scaled(QSize(150,150),aspectRatioMode=QtCore.Qt.KeepAspectRatio,transformMode=QtCore.Qt.SmoothTransformation) # image_widget.setScaledContents(True) self._video_widget.setPixmap(pixmap)
Example #30
Source File: common.py From detection with GNU General Public License v2.0 | 5 votes |
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)