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. Jpg images doesn't load properly - only white background
Qt 6.11 is out! See what's new in the release blog

Jpg images doesn't load properly - only white background

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.3k Views 2 Watching
  • 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.
  • N Offline
    N Offline
    never_ever
    wrote on last edited by never_ever
    #1

    Hi,
    I have some pairs of JPG images that I want to load. Problem is that I get only white background (no image is visible although founction load return true). First I thought that there is problem with .jpg image format plugin and I copy jpeg.dll to folder "plugins/imageformats" in my project path. But it still doesn't work.

    void ImageGUI::loadImagesForStereo()
    {
       QStringList imagesList1 = QFileDialog::getOpenFileNames(this, tr("Open images from left camera"), ".", tr("JPG files (*.jpg)"));
       QStringList imagesList2 = QFileDialog::getOpenFileNames(this, tr("Open images from left camera"), ".", tr("JPG files (*.jpg)"));
       if(imagesList1.size() > 0 && imagesList2.size() > 0)
         ImageClass::startOfflineCalib(imagesList1, imagesList2);
       else
       {
         QString str;
         str = tr("No images for ");
         if(imagesList1.size() <=0 && imagesList2.size() <= 0)
           str += tr("left & right view chosen");
         else if(imagesList1.size() <= 0)
           str += tr("left view chosen");
         else if(imagesList2.size() <= 0)
           str += tr("right view chosen");
    
         ui.teInfo->append(str);
       }
    }
    
    bool ImageClass::startOfflineCalib(QStringList imagesLeft, QStringList imagesRight)
    {
      m_imageList1.clear();
      m_imageList2.clear();
    
      
      if(imagesLeft.size() != imagesRight.size())
        return false;
    
      for(int i = 0; i < imagesLeft.size(); i++)
      {
        QImage image1;
        bool success1 = image1.load(imagesLeft[i]);
        QString path = QDir::currentPath();
        QString tmpStr = imagesLeft[i];
        
       
        qDebug()<<tmpStr;
    
    //TEST: image display
        QPixmap* pm = new QPixmap();
        qDebug()<<i<<"loaded: "<<pm->load(tmpStr, ".jpg");
        QLabel lbl;
        lbl.setPixmap(*pm);
        lbl.show();
    // END TEST
       
        cv::Mat tmpMat1(image1.height(), image1.width(), CV_8UC3, (uchar*)image1.bits(),image1.bytesPerLine());
        cv::Mat imageMat1; 
        //cvtColor(tmpMat1, imageMat1,CV_BGR2RGB);
        
        QImage image2;
        bool success2 = image2.load(imagesRight[i]);
        cv::Mat tmpMat2(image2.height(), image2.width(), CV_8UC3, (uchar*)image2.bits(),image2.bytesPerLine());
        cv::Mat imageMat2; 
       // cvtColor(tmpMat2, imageMat2,CV_BGR2RGB);
    
        if(success1 && success2)
        {
          m_imageList1.append(imageMat1);
          m_imageList2.append(imageMat2);
        }
      }
    }
    

    Any ideas why I get only white label?

    • label expands to image size
    • image->isNull() returns false;
    • jpeg.dll is definitely loaded (info from visual output).
    • JPG images properly saves to files, I can't only load them
    • I add to main file QApplication::addLibraryPath("plugins/imageformats") (I don't how exactly it should looks like so I have tried also "./plugins/imageformats", "plugins/"
    1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #2

      Hi,
      in this code you load into tmpMat* and add empty imageMat* to your list.
      -Michael.

      1 Reply Last reply
      1
      • N Offline
        N Offline
        never_ever
        wrote on last edited by
        #3

        Ok, the lines cvtColor(tmpMat1, imageMat1, CV_BGR2RGB) was commented for tests after I realized that jpg isn't loading. More important are lines of code that are higher (between TEST and END TEST comments and some lines higher), because there I try to test why it doesn't load my images.

        1 Reply Last reply
        0
        • m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #4

          Can you give a link to one of these problematic jpeg images, maybe there is something special about the images.
          -Michael.

          N 2 Replies Last reply
          0
          • m.sueM m.sue

            Can you give a link to one of these problematic jpeg images, maybe there is something special about the images.
            -Michael.

            N Offline
            N Offline
            never_ever
            wrote on last edited by
            #5

            @m.sue Yes, but I can do it for 5-6 hours when I will have directly access to my computer

            1 Reply Last reply
            0
            • m.sueM m.sue

              Can you give a link to one of these problematic jpeg images, maybe there is something special about the images.
              -Michael.

              N Offline
              N Offline
              never_ever
              wrote on last edited by
              #6

              @m.sue Ok I upload image to one of the host: one of the images from sequence

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                Loading your image with this quick written application works fine:

                #include <QtWidgets>
                
                int main(int argc, char *argv[])
                {
                    QApplication app(argc, argv);
                    QLabel label;
                    label.setPixmap(QPixmap("6f81f00d48.jpg"));
                    label.show();
                    return app.exec();
                }
                

                One thing in your code. There's no need to allocated the QPixmap on heap.

                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
                1
                • m.sueM Offline
                  m.sueM Offline
                  m.sue
                  wrote on last edited by m.sue
                  #8

                  Hi,
                  your image looks ok, your code looks ok (maybe write "JPG" instead of ".jpg", or just call without an image type hint). So there has to be another problem:
                  Does imagesLeft[i] contain an absolute path and the correct path to the image? I see that you check the directory, so maybe you already assumed something in this direction?
                  -Michael.

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    never_ever
                    wrote on last edited by
                    #9

                    Now it works fine (I have no idea why it didn't work earlier). However, I decided to use opencv function imread() because I must use cv::Mat later, and it is better to read it by opencv function than transform from QImage to cv::Mat

                    Btw I have tried to transform from QImage to cv::Mat

                    QImage image;
                    bool success = image.load(imagesRight[i]);
                    cv::Mat tmpMat(image.height(), image.width(), CV_8UC3, (uchar*)image.bits(),image.bytesPerLine());
                    

                    but if I display that tmpMat

                    imshow("after", tmpMat);
                    

                    I get image that has vertical strips (sth like this image after transformation

                    In other part of my program I acquire images from camera as IplImage. I change them to cv::Mat and then to QImage and save and it works fine. Why it doesn't work the other way?

                    1 Reply Last reply
                    0

                    • Login

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