qimage

What is the difference between QImage and QPixmap?

女生的网名这么多〃 提交于 2019-11-28 04:37:00
I do not understand what is the difference between QImage and QPixmap, they seem to offer the same functionality. When should I use a QImage and when should I use a QPixmap? karlphillip Easilly answered by reading the docs on QImage and QPixmap : The QPixmap class is an off-screen image representation that can be used as a paint device. The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device. Edit: Also, from @Dave's answer: You can't manipulate a QPixmap outside the GUI-thread, but QImage has no such

Convert a QImage to grayscale

六眼飞鱼酱① 提交于 2019-11-28 00:07:08
I have a QImage and I need to convert it to grayscale, then later paint over that with colors. I found an allGray() and isGrayScale() function to check if an image is already grayscale, but no toGrayScale() or similarly-named function. Right now I'm using this code, but it's does not have a very good performance: for (int ii = 0; ii < image.width(); ii++) { for (int jj = 0; jj < image.height(); jj++) { int gray = qGray(image.pixel(ii, jj)); image.setPixel(ii, jj, QColor(gray, gray, gray).rgb()); } } What would be the best way, performance-wise, to convert a QImage to grayscale? UmNyobe Rather

Applying overlays to image with varying transparency

南笙酒味 提交于 2019-11-27 16:31:11
I have got a RGB image (224x224x3) and an overlay (224x224). Now I want to apply my overlay as red pixels on my RGB image, which I make therefore to grayscale. The overlay range from 0 to 255. Higher values should make a stronger red. I tried to use Stefan's tutorial, but I could not adapt it: tutorial . Here is my code: # RGB input, shape (224x224x3) img = self.inputImage # make to grayscale img = np.average(img, axis=2) rows, cols = img.shape[0], img.shape[1] color_mask = np.zeros((rows, cols, 3)) # convert to uint8 to plot in QImage::Format_RGB888 img = img.astype(np.uint8) overlay = self

Display QImage with QtGui

久未见 提交于 2019-11-27 11:07:05
I am new to Qt, and I am trying to create a simple GUI Application that displays an image once a button has been clicked on. I can read the image in a QImage object, but is there any simple way to call a Qt function that takes the QImage as an input, and displays it? Simple, but complete example showing how to display QImage might look like this: #include <QtGui/QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplication a(argc, argv); QImage myImage; myImage.load("test.png"); QLabel myLabel; myLabel.setPixmap(QPixmap::fromImage(myImage)); myLabel.show(); return a.exec(); }

What is the difference between an opencv BGR image and its reverse version RGB image[:,:,::-1]?

笑着哭i 提交于 2019-11-27 05:39:13
I'm trying to show an opencv image with a QLabel. I got two different versions of the image, first one is the opencv BGR image, the second one is the RGB image using image[:,:,::-1], the BGR version works fine but the RGB version doesn't work. The following code works fine src = cv.imread('image.jpg') h,w,ch = src.shape bytesPerLine = ch * w qImg = QImage(src.data, w, h, bytesPerLine, QImage.Format_RGB888) qImg = qImg.rgbSwapped() self.ui.label.setPixmap(QPixmap.fromImage(qImg)) These code doesn't work : src = cv.imread('image.jpg') src = src[:,:,::-1] h,w,ch = src.shape bytesPerLine = ch * w

What is the difference between QImage and QPixmap?

≡放荡痞女 提交于 2019-11-27 05:14:19
问题 I do not understand what is the difference between QImage and QPixmap, they seem to offer the same functionality. When should I use a QImage and when should I use a QPixmap? 回答1: Easilly answered by reading the docs on QImage and QPixmap: The QPixmap class is an off-screen image representation that can be used as a paint device. The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device. Edit: Also, from

Convert a QImage to grayscale

别说谁变了你拦得住时间么 提交于 2019-11-27 04:42:07
问题 I have a QImage and I need to convert it to grayscale, then later paint over that with colors. I found an allGray() and isGrayScale() function to check if an image is already grayscale, but no toGrayScale() or similarly-named function. Right now I'm using this code, but it's does not have a very good performance: for (int ii = 0; ii < image.width(); ii++) { for (int jj = 0; jj < image.height(); jj++) { int gray = qGray(image.pixel(ii, jj)); image.setPixel(ii, jj, QColor(gray, gray, gray).rgb(

`QImage` constructor has unknown keyword `data`

北战南征 提交于 2019-11-27 02:24:38
Suppose I am taking an image from the webcam using opencv. _, img = self.cap.read() # numpy.ndarray (480, 640, 3) Then I create a QImage qimg using img : qimg = QImage( data=img, width=img.shape[1], height=img.shape[0], bytesPerLine=img.strides[0], format=QImage.Format_Indexed8) But it gives an error saying that: TypeError: 'data' is an unknown keyword argument But said in this documentation, the constructor should have an argument named data . I am using anaconda environment to run this project. opencv version = 3.1.4 pyqt version = 5.9.2 numpy version = 1.15.0 What they are indicating is

Using QImage with OpenGL

梦想的初衷 提交于 2019-11-27 02:20:36
问题 I've very recently picked up Qt and am using it with OpenGL The thing though is that when moving my SDL code to Qt and changing the texture code to use QImage it stops working. The image does load correctly, as shown through the error checking code. Thanks! P.S: Please don't suggest I use glDrawPixels, I need to fix the problem at hand. Some of the reasons for that being 1. slow 2. android (which this code may be running on eventually) is OpenGL ES and does not support glDrawPixels Here's the

Enabling JPEG support for QImage in py2exe-compiled Python scripts?

假如想象 提交于 2019-11-27 01:53:09
I'm trying to use a JPEG image in a QImage object from a Python script, with PyQt4. The script itself works perfectly, the image loads and can be manipulated and rendered and all. However, when I try to "compile" this script with py2exe, everything works but the JPEG image. Replacing it with a PNG equivalent works, but since my program downloads images from the web, they won't always be in PNG format and I can't afford converting them all with another library. I've discovered that JPEG image support for QImage, along with other image formats, is provided by some DLLs in the \qt\plugins