qpixmap

C++ opencv Mat to QPixmap errors

匆匆过客 提交于 2020-01-03 02:28:08
问题 I am attempting to write a function which puts a greyscale OpenCv Mat into a Qt QPixmap, then into a QLabel. A third of the time it works. A third of the time, it skews the image... becomes The rest of the time, the program crashes, specifically on the fromImage() line. I know that the incoming Mat objects are greyscale and non-null in each case. Here is the code in question... void MainWindow::updateCanvasLabel(Mat mat){ imwrite("c:/pics/last-opened.jpg", mat); //to verify that Mat is //

How to load an image with QLabel in PySide2

大城市里の小女人 提交于 2020-01-03 00:38:20
问题 I'm a beginner in coding and python. I read that tkinter is a bit to "basic" if you want to develop an application which is a a bit more complicated and PyQt is problematic for licencing. This is why I chose PySide2 in order to develop this kind of project, but found so far the documentation relatively scarce. Is this the right choice? My present coding problem is the following: I'm Trying to load an image with PySide2 without success. Here is the code of my 2 attempts: Attempt N°1: import

How to add both an image and text to a QLabel

扶醉桌前 提交于 2020-01-02 07:23:08
问题 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

How to add both an image and text to a QLabel

倖福魔咒の 提交于 2020-01-02 07:23:03
问题 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

Load blob image data into QPixmap

吃可爱长大的小学妹 提交于 2020-01-01 03:12:12
问题 I am writing a program using PyQt4 for front-end GUI and this program accesses a back-end database (which can be either MySQL or SQLite). I need to store some image data in the database and below is the Python code I use to import image files (in JPEG format) to a blob data field in the database: def dump_image(imgfile): i = open(imgfile, 'rb') i.seek(0) w = i.read() i.close() return cPickle.dumps(w,1) blob = dump_image(imgfile) hex_str = blob.encode('hex') # x"%s"%hex_str will be the string

How to center QPixmap while Painting it inside QItemDelegate of QListWidget

两盒软妹~` 提交于 2019-12-25 18:48:12
问题 I'm painting a QPixmap inside the QItemDelegate of QListWidget. Each QListWidgetItem is of different dimensions. Inside the void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) function of QItemDelegate, I want to paint QPixmap with center Alignment inside the QListWidgetItem. option.rect() gives the geometry of the item with which I can calculate the center position and paint accordingly, but I want to know the better approach for this alignment.Can

QLabel OpenCV Image Coordinates in Qt

安稳与你 提交于 2019-12-24 13:23:13
问题 I would like to do manipulations on the image with OpenCV based on mouseClicks. I am using QLabel to display cv::Mat images. Now my problem is with getting the mouse clicks positions with respect to the image. So, I would like (0,0) at topleft corner of the image. Following is my mousePressEvent, but these are not correct co-ordinates. void MainWindow::mousePressEvent( QMouseEvent* ev ) { //This seems to work thanks to Pavel QPoint P = ui->label->mapFrom(this, ev->pos()) //if( ui->label-

Qt QImage to QPixmap Conversion loses Color Information for UI

好久不见. 提交于 2019-12-24 05:11:56
问题 I am trying to update a QPixmap on a QLabel in my main Qt UI. The following slot is called to do this with the "newImage" variable QImage ( because it's from a different thread ). The QImage is converted to someImage with convertFromImage ( I've also tried ::fromImage ). If I just save the QImage "newImage" to file, I get a green rectangle and red text that I draw with OpenCV earlier on, however, if I save the converted pixmap OR show the converted pixmap I lose the color for the rectangle

How to convert a cv::Mat to QImage or QPixmap?

匆匆过客 提交于 2019-12-24 04:11:00
问题 I've tried to look around and tried everything I've found, but haven't found a solution for this problem. I'm trying to update an image in a QT application by button click. In the constructor I've managed to show a image: cv::Mat temp = cv::Mat(*this->cv_size,CV_8UC3); temp = cv::Scalar(0,255,155); ui->image->setPixmap(QPixmap::fromImage( Mat2QImage(temp))); And then I've created a button and linked this function to it void UIQT::refreshImage(){ cv::Mat temp = cv::Mat(*this->cv_size,CV_8UC3);

Better way to load QPixmap data

情到浓时终转凉″ 提交于 2019-12-23 19:41:07
问题 Better way to do it (without QImage )?: QImage image(width, height, QImage::Format_RGB888); memcpy(image.bits(), m_frameRGB->data[0], height * width * 3); QPixmap pixmap = QPixmap::fromImage(image); I don't see any reason to use QImage as intermediate buffer, but QPixmap::loadFromData don't load data with this context: pixmap.loadFromData(m_frameRGB->data[0], height * width * 3); // Need pixmap resize? 回答1: The documentation says: "If the format is not specified (which is the default), the