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. Corrupt JPEG data error
Forum Update on Monday, May 27th 2025

Corrupt JPEG data error

Scheduled Pinned Locked Moved Solved General and Desktop
qcameracaptureimagescmakeqt 5.9.5
9 Posts 5 Posters 3.8k 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.
  • B Offline
    B Offline
    BartoszPaj
    wrote on 25 Sept 2018, 11:26 last edited by
    #1

    Hi,
    when I try capture image i get error:
    Corrupt JPEG data: premature end of data segment

    Note:
    Capture rate: 1shot/750ms
    Wait for read image 1 sec.
    Resolution 640x480

    I suppose it could be problem with libjpeg, but I don't know how to force use it in CMake project.

    R 1 Reply Last reply 25 Sept 2018, 13:59
    0
    • B Offline
      B Offline
      BartoszPaj
      wrote on 11 Oct 2018, 10:29 last edited by
      #9

      2nd UPDATE:

      Problem was by natural source. The light reflects from window into camera.
      2nd problem was using file as buffer.

      I solved it by using grab image from QCameraViewFinder widget and send by memory.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        VRonin
        wrote on 25 Sept 2018, 11:54 last edited by
        #2

        A bit too generic.
        Can you show us some code?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0
        • B BartoszPaj
          25 Sept 2018, 11:26

          Hi,
          when I try capture image i get error:
          Corrupt JPEG data: premature end of data segment

          Note:
          Capture rate: 1shot/750ms
          Wait for read image 1 sec.
          Resolution 640x480

          I suppose it could be problem with libjpeg, but I don't know how to force use it in CMake project.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 25 Sept 2018, 13:59 last edited by
          #3

          @BartoszPaj

          I suppose it could be problem with libjpeg, but I don't know how to force use it in CMake project.

          first of all where does the JPEG data come from?
          second no need to do anything in your CMake project, since the jpeg codec/plugin is already compiled and shipped with Qt.
          Maybe you can save an example to a file to reproduce the issue?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pedro6
            Banned
            wrote on 25 Sept 2018, 16:25 last edited by
            #4
            This post is deleted!
            1 Reply Last reply
            -1
            • B Offline
              B Offline
              BartoszPaj
              wrote on 25 Sept 2018, 18:13 last edited by
              #5

              @VRonin

              // This is slot connected to QTimer (timeout 750ms)
              
              void FormAuthorizationPanel::takeQrPhoto()
              {
                  camera->searchAndLock();
              
                  QEventLoop loop;
                 QObject::connect(imageCapture,SIGNAL(readyForCaptureChanged(bool)),&loop,SLOT(quit()));
                      imageCapture->capture(QString(QCoreApplication::applicationDirPath()+"/"+"QrShot"));
                  loop.exec();
              
                  qrCaptureMan->grabQrStatus();
                  camera->unlock();
              
              }
              
              void QrCaptureManager::grabQrStatus()
              {
                  auto f = std::async(std::launch::async,&QrCaptureManager::readQrCode,this);
                  qDebug() << "Waiting ...";
                  std::future_status status;
                  do{
                      status = f.wait_for(std::chrono::seconds(1));
                      if (status == std::future_status::deferred){
                          qDebug() << "deferred\n";
                      } else if (status == std::future_status::timeout) {
                          qDebug() << "timeout\n";
                      } else if (status == std::future_status::ready) {
                          if(f.get()){
                              emit QrCodeStatus(true);
                              QrTimer->stop();
                          }else{
                              emit QrCodeStatus(false);
                          }
              
                      }
                  }while(status != std::future_status::ready);
              }
              
              bool QrCaptureManager::readQrCode()
              {
                  QImage img;
                  if(!img.load(QString(QCoreApplication::applicationDirPath()+"/QrShot.jpg"))){
                      qDebug() << "Img load error";
                      return false;
                  }
                  decoder = new QZXing();
                  decoder->setDecoder(QZXing::DecoderFormat_QR_CODE);
              
                  if(decoder->decodeImage(img).isEmpty()){
                      qDebug() << "QrCode Failed";
                      decoder->deleteLater();
                      return false;
                  }
                  else{
                      setUpCardInfo(decoder->decodeImage(img));
                      qDebug() << "Qr read correct";
                      decoder->deleteLater();
                      return true;
                  }
              }
              
              // This is how I setup camera 
              
              void FormAuthorizationPanel::setUpCamera(const QCameraInfo &cameraInfo)
              {
                  delete imageCapture;
                  delete camera;
                  delete vfs;
              
                  camera = new QCamera(cameraInfo);
                  vfs = new QCameraViewfinderSettings();
                  vfs->setResolution(640,480);
              
                  camera->setViewfinder(ui->widget);
                  camera->setViewfinderSettings(*vfs);
              
                  imageCapture = new QCameraImageCapture(camera);
                  camera->start();
                  imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
                  ui->widget->update();
                  cameraStatus = true;
              }
              
              

              @raven-worx said in Corrupt JPEG data error:

              @BartoszPaj

              I suppose it could be problem with libjpeg, but I don't know how to force use it in CMake project.

              first of all where does the JPEG data come from?

              If I understand data came from QCameraImageCapture.

              @raven-worx said in Corrupt JPEG data error:

              second no need to do anything in your CMake project, since the jpeg codec/plugin is already compiled and shipped with Qt.
              Maybe you can save an example to a file to reproduce the issue?

              I suggested by this topic: https://stackoverflow.com/questions/33198296/qt-load-incomplete-jpeg-data-into-qpixmap-how-to-verify.
              No, I can't. That's all what I could show code ( Company Terms).

              1 Reply Last reply
              0
              • V Offline
                V Offline
                VRonin
                wrote on 25 Sept 2018, 18:20 last edited by VRonin
                #6

                Why are you connecting to readyForCaptureChanged?
                try:

                QEventLoop loop;
                int captureID = -1;
                QObject::connect(imageCapture,&QCameraImageCapture::imageSaved,&loop,[&captureID,&loop](int capID)->void{
                if(capID==captureID)
                loop.quit();
                });
                captureID = imageCapture->capture(QString(QCoreApplication::applicationDirPath()+"/"+"QrShot"));
                loop.exec();
                

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                B 1 Reply Last reply 25 Sept 2018, 18:26
                1
                • V VRonin
                  25 Sept 2018, 18:20

                  Why are you connecting to readyForCaptureChanged?
                  try:

                  QEventLoop loop;
                  int captureID = -1;
                  QObject::connect(imageCapture,&QCameraImageCapture::imageSaved,&loop,[&captureID,&loop](int capID)->void{
                  if(capID==captureID)
                  loop.quit();
                  });
                  captureID = imageCapture->capture(QString(QCoreApplication::applicationDirPath()+"/"+"QrShot"));
                  loop.exec();
                  
                  B Offline
                  B Offline
                  BartoszPaj
                  wrote on 25 Sept 2018, 18:26 last edited by BartoszPaj
                  #7

                  Before, when Timeout was shorter (<500ms) the app could crash. So I was created a loop for stop the camera.

                  UPDATE: Thank you for advice. Now I have much better synchro.
                  Today I tested app in another device. I'm gonna suppose it could be fault by low quality camera.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DaveWK
                    wrote on 10 Oct 2018, 10:38 last edited by
                    #8
                    This post is deleted!
                    1 Reply Last reply
                    -1
                    • B Offline
                      B Offline
                      BartoszPaj
                      wrote on 11 Oct 2018, 10:29 last edited by
                      #9

                      2nd UPDATE:

                      Problem was by natural source. The light reflects from window into camera.
                      2nd problem was using file as buffer.

                      I solved it by using grab image from QCameraViewFinder widget and send by memory.

                      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