Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Jpg images doesn't load properly - only white background



  • 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/"


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



  • 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.



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



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



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


  • Lifetime Qt Champion

    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.



  • 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.



  • 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?


Log in to reply