qpixmap

Convert PyQt5 QPixmap to numpy ndarray

谁都会走 提交于 2019-12-06 06:20:32
问题 I have pixmap: pixmap = self._screen.grabWindow(0, self._x, self._y, self._width, self._height) I want to convert it to OpenCV format. I tried to convert it to numpy.ndarray as described here but I got error sip.voidptr object has an unknown size Is there any way to get numpy array (same format as cv2.VideoCapture read method returns)? 回答1: I got numpy array using this code: channels_count = 4 pixmap = self._screen.grabWindow(0, self._x, self._y, self._width, self._height) image = pixmap

How to show pixel position and color from a QGraphicsPixmapItem

◇◆丶佛笑我妖孽 提交于 2019-12-06 05:51:32
问题 I'm developing a custom widget with QGraphicsScene/View and I have no prior experience with it. The custom widget is an image viewer that needs to track mouse movement and send signal(s) to it's parent dialog / window. The signal(s) will be the position of the pixel under the mouse cursor and it's color (in RGB). A status bar will use that information. I use a QGraphicsPixmapItem to display the image I load from a file in the scene. Thanks. 回答1: First of all you have to implement the

how to remove extra margins arounding a QPixmap?

馋奶兔 提交于 2019-12-06 04:24:20
I draw a QRectF in the paint function of my class and set a QPixmap as brush for it. I build an object from a class containing this QRectF . When I put this item in my scene and set background for the scene the QRectF appears. It also occurs for a QPixmap that I add to the scene. What can I do to remove the extra margins? void MyQgraphicsObject::paint(QPainter *painter, ) { QRectF rec(0,0,50,60); QPixmap pi(":picture/im/super.jpg"); pi=pi.scaled(50,60); painter->setBrush(QBrush(pi)); painter->setPen(Qt::NoPen); painter->drawRoundedRect(rec,10,10); } //////////////////// QPixmap a(":picture/im

Why is there bit shifting when converting to an image from an array?

匆匆过客 提交于 2019-12-06 04:20:11
I'm trying to create a QPixmap from a numpy array. The numpy array image is going to be 2D (ie no color info just grayscale). I'm trying to adapt this answer to my needs however I don't quite understand this line: b = (255 << 24 | a[:,:,0] << 16 | a[:,:,1] << 8 | a[:,:,2]).flatten() # pack RGB values There is some bitshifting going on and some bitwise or ' ing but I don't quite get it to be honest. So my dumbed down example is as follows: x, y = np.meshgrid(np.arange(1920), np.arange(1080), indexing='ij'); z = np.sin(0.03*x)*np.cos(0.005*y) imgPNFN = z if imgPNFN.ndim == 2: imgPNFN = imgPNFN[:

Shifting the hue of a QImage / QPixmap

浪子不回头ぞ 提交于 2019-12-06 04:01:17
问题 I suppose this is more of a graphics manipulation question in general, but I'd like to accomplish this in Qt (c++). If I have an image - let's just say a circle on a transparent background - of a light gray color, is there any built-in functionality in Qt to shift the hue / saturation to color it? I suppose I could go pixel by pixel, and modifying the rgb mathematically - add x to r, g, and b, to get a desired color, but there must be a better way than modifying every single pixel. Nothing in

QGraphicsView scrolling and image scaling/cropping

萝らか妹 提交于 2019-12-06 03:06:21
问题 I would like to have a background image in my QGraphicsView that is always scaled (and cropped if necessary) to the size of the viewport, without scrollbars and without scrolling with the keyboard and mouse. The example below is what I am doing to scale and crop an image in the viewport, but I am using random values for the cropping that are pulled out of the aether. I would like a logical solution? MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui-

Draw on top of image

怎甘沉沦 提交于 2019-12-06 02:59:59
问题 I'm new to PyQt5 and I couldn't find any answers that worked for me about how to draw with QPainter on top of a loaded image (QPixmap("myPic.png")). I tried doing it within a paintEvent method but it didn't work. If I want to draw a line on top of the loaded image in the snippet below, how would I go about doing it? import sys from PyQt5.QtWidgets import * from PyQt5.QtGui import * class Example(QWidget): def __init__(self): super().__init__() self.setGeometry(30, 30, 500, 300) self.initUI()

How to add both an image and text to a QLabel

好久不见. 提交于 2019-12-06 01:38:55
I have a QHBoxLayout with a QLabel in it, and I'm trying to get both an icon and window title text in the QLabel. Is that possible? Or even to add the icon directly to the QHBoxLayout, so that is is laying just before the window title text? Here is my code: class MyBar(QWidget): def __init__(self, parent): super(MyBar, self).__init__() self.parent = parent self.layout = QHBoxLayout() self.layout.setContentsMargins(0,0,0,0) self.title = QLabel("Main Window") def changetitle(self, msg): self.title.setText(msg) Edit: Here is the code where I used two labels side by side: self.label3 = QLabel(self

Saving QPixmap to JPEG failing (Qt 4.5)

陌路散爱 提交于 2019-12-06 01:13:05
I have the following code. QString fileName = QFileDialog::getSaveFileName( this, tr("Output Image file"), (""), tr("PNG (*.png);;JPEG (*.JPEG);;Windows Bitmap (*.bmp);;All Files (*.*)") ); if(fileName != "") { QwtPlot* pPlot = ... QSize size = pPlot->size(); QRect printingRect(QPoint(0, 0), size); QPixmap pixmapPrinter(size); pixmapPrinter.fill(Qt::white); { QPainter painter(&pixmapPrinter); pPlot->print(&painter, printingRect); } bool isOk = pixmapPrinter.save(fileName); if(!isOk) { QString msgText = tr("Failed to write into ") + fileName; QMessageBox::critical(this, tr("Error Writing"),

Scaled QPixmap looks bad

ぃ、小莉子 提交于 2019-12-05 17:44:44
I have the following widget: pixmap = QtGui.QPixmap(r'pics\cdaudio.png').scaled(100, 100) The image is scaled down, from 256x256. It looks pretty choppy: How can I scale it smoothly from within Qt? Use the transformMode parameter: pixmap = QtGui.QPixmap(r'pics\cdaudio.png').scaled(100, 100, transformMode=QtCore.Qt.SmoothTransformation) According to @iTayb, here's what I came up with: // Scale the source to the requested size with // the KeepAspectRatio as aspectMode & SmoothTransformation as mode *source = source->scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); target-