Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCamera has strange blue tint
QtWS25 Last Chance

QCamera has strange blue tint

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcamera
25 Posts 8 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SolaVitae
    wrote on 28 May 2019, 18:40 last edited by
    #1

    Currently, my QCamera/viewfinder has a very strange blue tint, as seen here

    alt text

    This is the original image

    alt text

    I'm using a virtual webcam for testing, but the tint issue is the same on my actual webcam as well. Using the built-in windows Camera app has no blue tint, and the image appears fine. I'm using the built-in QCamera example from creator as well for testing

    J 1 Reply Last reply 29 May 2019, 04:26
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 28 May 2019, 19:35 last edited by
      #2

      yes, it does. Is there a question in there?

      Have you verified that the color model output of the camera is what Qt thinks it is? is it JPG or one of the many YUV image formats?

      S 1 Reply Last reply 28 May 2019, 19:40
      1
      • K Kent-Dorfman
        28 May 2019, 19:35

        yes, it does. Is there a question in there?

        Have you verified that the color model output of the camera is what Qt thinks it is? is it JPG or one of the many YUV image formats?

        S Offline
        S Offline
        SolaVitae
        wrote on 28 May 2019, 19:40 last edited by
        #3

        @Kent-Dorfman
        I guess the question would be how do I get rid of it; would the expected image format be an issue even with a virtual webcam?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kent-Dorfman
          wrote on 28 May 2019, 19:43 last edited by
          #4

          oh...virtual webcam problem with ALL images, or just ones captured from the real camera?

          S 1 Reply Last reply 28 May 2019, 20:01
          0
          • K Kent-Dorfman
            28 May 2019, 19:43

            oh...virtual webcam problem with ALL images, or just ones captured from the real camera?

            S Offline
            S Offline
            SolaVitae
            wrote on 28 May 2019, 20:01 last edited by
            #5

            @Kent-Dorfman

            The virtual webcam just emulates a webcam and let's you show something like your desktop, or a still image (it shows up as a separate device on the device list) I'm only using it to see if the blue tint was an issue with my actual webcam, but both my actual webcam and the virtual webcam both have the blue tint, but only in QT, as images captured outside of QT look perfectly normal

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kent-Dorfman
              wrote on 28 May 2019, 20:55 last edited by
              #6

              I understand that. what I'm asking is whether the affected source images all originate from the real camera, or if the tint is experienced with generic images from other sources (piped thru the virtual device).

              S 1 Reply Last reply 29 May 2019, 11:54
              0
              • S SolaVitae
                28 May 2019, 18:40

                Currently, my QCamera/viewfinder has a very strange blue tint, as seen here

                alt text

                This is the original image

                alt text

                I'm using a virtual webcam for testing, but the tint issue is the same on my actual webcam as well. Using the built-in windows Camera app has no blue tint, and the image appears fine. I'm using the built-in QCamera example from creator as well for testing

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 29 May 2019, 04:26 last edited by
                #7

                @SolaVitae Looks like red part of the pixel data is missing. Can you show how you're using the camera?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • K Kent-Dorfman
                  28 May 2019, 20:55

                  I understand that. what I'm asking is whether the affected source images all originate from the real camera, or if the tint is experienced with generic images from other sources (piped thru the virtual device).

                  S Offline
                  S Offline
                  SolaVitae
                  wrote on 29 May 2019, 11:54 last edited by
                  #8

                  @Kent-Dorfman
                  the source image on the virtual cam is not from the real camera, its a .mp3 file, the issue also persists with just a standard .jpg file as the source as well.

                  @jsulm

                  in my application im using it as such:

                  WebCamDialog::WebCamDialog(QWidget *parent) :
                  	QDialog(parent),
                  	ui(new Ui::webcamdialog)
                  {
                  	ui->setupUi(this);
                  
                  	includeNameCB = ui->includeNameCB;
                  	includeNameLE = ui->includeNameLE;
                  	saveImageButton = ui->savePhotoButton;
                  	cancelButton = ui->exitButton;
                  
                  	availableCameras = ui->availableCamerasLW;
                  	
                  
                  	if (!checkCameraAvailability()) close();
                  
                  	availableCameras->setFocusPolicy(Qt::NoFocus);
                  	availableCameras->setPalette(p);
                  
                  	cameraList = QCameraInfo::availableCameras();
                  	QButtonGroup bg;
                  	bool firstOption = true;
                  	foreach(const QCameraInfo &ci, cameraList) {
                  		QCheckBox *cam = new QCheckBox(ci.description());
                  		bg.addButton(cam);
                  		cam->setAutoExclusive(true);
                  		QListWidgetItem *lwi = new QListWidgetItem();
                  		availableCameras->addItem(lwi);
                  		availableCameras->setItemWidget(lwi, cam);
                  		availableCameraMap.insert(cam, lwi);
                  		connect(cam, &QCheckBox::stateChanged, this, &WebCamDialog::cameraSelectionChanged);
                  		if (firstOption) {
                  			cam->setChecked(true);
                  			firstOption = false;
                  		}
                  	}
                  	bg.setExclusive(true);	
                  }
                  
                  
                  void WebCamDialog::setCamera(const QCameraInfo &c) {
                  	m_camera.reset(new QCamera(c));
                  	m_camera->setViewfinder(ui->viewFinder);
                  	m_camera->viewfinderSettings().setResolution(1000, 1000);
                  	m_camera->setCaptureMode(QCamera::CaptureStillImage);
                  
                  	m_camera->imageProcessing()->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceVendor);
                  
                  	qDebug() << m_camera->imageProcessing()->whiteBalanceMode();
                  	qDebug() << m_camera->imageProcessing()->colorFilter();
                  
                  
                  	m_imageCapture.reset(new QCameraImageCapture(m_camera.data()));
                  	connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &WebCamDialog::imageCaptured);
                  	m_camera->start();
                  
                  
                  }
                  
                  void WebCamDialog::imageCaptured(int id, const QImage &i) {
                  	Q_UNUSED(id);
                  	QImage destination;
                  	if (!overlay.isHidden()) destination = QImage(640, 530, QImage::Format_A2RGB30_Premultiplied);
                  	else destination = QImage(640, 480, QImage::Format_A2RGB30_Premultiplied);
                  
                  	QPainter p(&destination);
                  
                  	p.setCompositionMode(QPainter::CompositionMode_Source);
                  	p.fillRect(destination.rect(), Qt::white);
                  
                  	p.setCompositionMode(QPainter::CompositionMode_SourceOver);
                  	p.drawImage(0, 0, i);
                  	
                  	p.end();
                  	destination.save(c.directory + "\\" + ui->fileNameLE->text());
                  
                  }
                  
                  

                  there is a lot of other unrelated code that I removed, but that is everything directly pertaining to the camera and viewfinder. I also have the same issue with the built in QT Camera example in QT Creator though

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mranger90
                    wrote on 29 May 2019, 12:01 last edited by
                    #9

                    @SolaVitae said in QCamera has strange blue tint:

                    QImage(640, 480, QImage::Format_A2RGB30_Premultiplied);

                    Blue tint could be because the red and blue channels are swapped. If you are in windows this is a common problem. Try using Format_A2BGR30_Premultiplied, when creating the QImage.

                    S 1 Reply Last reply 29 May 2019, 13:18
                    2
                    • K Offline
                      K Offline
                      Kent-Dorfman
                      wrote on 29 May 2019, 12:34 last edited by
                      #10

                      what mranger said...the color format that Qt expects to see is not what is being sent.

                      1 Reply Last reply
                      0
                      • M mranger90
                        29 May 2019, 12:01

                        @SolaVitae said in QCamera has strange blue tint:

                        QImage(640, 480, QImage::Format_A2RGB30_Premultiplied);

                        Blue tint could be because the red and blue channels are swapped. If you are in windows this is a common problem. Try using Format_A2BGR30_Premultiplied, when creating the QImage.

                        S Offline
                        S Offline
                        SolaVitae
                        wrote on 29 May 2019, 13:18 last edited by SolaVitae
                        #11

                        @mranger90
                        it's still blue, its also blue in the viewfinder before the image is even saved

                        side note: The camera works perfectly, and is not blue in the QML Example from QT Creator, but is blue in the regular QT Example

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          Kent-Dorfman
                          wrote on 29 May 2019, 15:58 last edited by Kent-Dorfman
                          #12

                          Try different values for QCameraImageProcessing::WhiteBalanceMode and see if they have any effect.

                          In particular look at the definition for the white balance value you are currently using. It says "base value", which would probably infer that there is a list of vender values starting at 1000, where the required value is specific to the product being used.

                          S 1 Reply Last reply 29 May 2019, 16:18
                          0
                          • K Kent-Dorfman
                            29 May 2019, 15:58

                            Try different values for QCameraImageProcessing::WhiteBalanceMode and see if they have any effect.

                            In particular look at the definition for the white balance value you are currently using. It says "base value", which would probably infer that there is a list of vender values starting at 1000, where the required value is specific to the product being used.

                            S Offline
                            S Offline
                            SolaVitae
                            wrote on 29 May 2019, 16:18 last edited by
                            #13

                            @Kent-Dorfman
                            ive tried all of them, with no change

                            I've narrowed the issue down to it inverting the red/blue colors

                            as seen in this image
                            alt text

                            The colors actually are Red - > Green - > Blue, but it inverts red and blue

                            1 Reply Last reply
                            2
                            • M Offline
                              M Offline
                              mranger90
                              wrote on 29 May 2019, 17:23 last edited by
                              #14

                              Ok, that's pretty much what I expected. The output from the camera is probably RGB but a lot of windows drivers are expecting BGR. Or it's possible (but less likely) that your camera is putting out BGR and the driver expects RGB. You might be able to change this by examining the QImageEncoderSettings to see if there is a pixel format and changing it. Or you can try intercepting the buffers and building a QImage based on the correct orientation.

                              S 1 Reply Last reply 29 May 2019, 17:48
                              1
                              • M mranger90
                                29 May 2019, 17:23

                                Ok, that's pretty much what I expected. The output from the camera is probably RGB but a lot of windows drivers are expecting BGR. Or it's possible (but less likely) that your camera is putting out BGR and the driver expects RGB. You might be able to change this by examining the QImageEncoderSettings to see if there is a pixel format and changing it. Or you can try intercepting the buffers and building a QImage based on the correct orientation.

                                S Offline
                                S Offline
                                SolaVitae
                                wrote on 29 May 2019, 17:48 last edited by
                                #15

                                @mranger90

                                Is there an easy way to do this? seems odd that it only occurs in QT, with both my actual webcam and a virtual one, but doesn't occur in an example using QML

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mranger90
                                  wrote on 29 May 2019, 18:08 last edited by mranger90
                                  #16

                                  You can check to see what the camera is supporting with

                                      QList<QVideoFrame::PixelFormat> formats = m_camera->supportedViewfinderPixelFormats();
                                      qDebug() << "supported formats " << formats;
                                  

                                  Then you might be able to do something like:

                                  viewFinderSettings.setPixelFormat(QVideoFrame::Format_RGB24);
                                  

                                  You might also want to check with some other application. As I recall, on windows the QCamera stuff is a rather thin layer over DirectShow so you might want to play with that to get a clear idea of whats coming off the camera.
                                  If worse comes to worst you may want to use something like OpenCV which will give you more control over the capture buffers and how to format them.

                                  S 1 Reply Last reply 29 May 2019, 18:54
                                  1
                                  • M mranger90
                                    29 May 2019, 18:08

                                    You can check to see what the camera is supporting with

                                        QList<QVideoFrame::PixelFormat> formats = m_camera->supportedViewfinderPixelFormats();
                                        qDebug() << "supported formats " << formats;
                                    

                                    Then you might be able to do something like:

                                    viewFinderSettings.setPixelFormat(QVideoFrame::Format_RGB24);
                                    

                                    You might also want to check with some other application. As I recall, on windows the QCamera stuff is a rather thin layer over DirectShow so you might want to play with that to get a clear idea of whats coming off the camera.
                                    If worse comes to worst you may want to use something like OpenCV which will give you more control over the capture buffers and how to format them.

                                    S Offline
                                    S Offline
                                    SolaVitae
                                    wrote on 29 May 2019, 18:54 last edited by
                                    #17

                                    @mranger90

                                    The list returns (Format_RGB24, Format_YUV420P), its default set to the RGB24, and changing it to YUV420p does nothing.

                                    As for testing it elsewhere, it works flawlessly everywhere else. The default camera app on windows works, a webcam testing website works, skype works.

                                    1 Reply Last reply
                                    0
                                    • fcarneyF Offline
                                      fcarneyF Offline
                                      fcarney
                                      wrote on 29 May 2019, 19:44 last edited by
                                      #18

                                      @SolaVitae,
                                      Just a shot in the dark. Have you tried explicitly setting the pixel format to QVideoFrame::Format_RGB24? Just in case some other app changed its mode?

                                      C++ is a perfectly valid school of magic.

                                      S 1 Reply Last reply 29 May 2019, 22:35
                                      0
                                      • fcarneyF fcarney
                                        29 May 2019, 19:44

                                        @SolaVitae,
                                        Just a shot in the dark. Have you tried explicitly setting the pixel format to QVideoFrame::Format_RGB24? Just in case some other app changed its mode?

                                        S Offline
                                        S Offline
                                        SolaVitae
                                        wrote on 29 May 2019, 22:35 last edited by SolaVitae
                                        #19

                                        @fcarney
                                        yes, it does not change anything

                                        The issue does not occur on my laptop, or a friend's PC. So im guessing it has something to do with my pc. What it is I can't figure out, but I guess it's not that big of a deal if it's only on my PC. It will subconciously bother me to no ender, but oh well

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 30 May 2019, 06:24 last edited by
                                          #20

                                          Hi,

                                          Since you are talking about a virtual camera, it might be generating BGR images. And since it's virtual you might be able to configure that.

                                          In any case, you can use QImage::rgbSwapped to convert to the right order.

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          2

                                          7/25

                                          29 May 2019, 04:26

                                          18 unread
                                          • Login

                                          • Login or register to search.
                                          7 out of 25
                                          • First post
                                            7/25
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved