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
QtWS25 Last Chance

Corrupt JPEG data error

Scheduled Pinned Locked Moved Solved General and Desktop
qcameracaptureimagescmakeqt 5.9.5
9 Posts 5 Posters 3.7k 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.
  • BartoszPajB Offline
    BartoszPajB Offline
    BartoszPaj
    wrote on 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.

    raven-worxR 1 Reply Last reply
    0
    • BartoszPajB Offline
      BartoszPajB Offline
      BartoszPaj
      wrote on 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
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on 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
        • BartoszPajB BartoszPaj

          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.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on 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 last edited by
            #4
            This post is deleted!
            1 Reply Last reply
            -1
            • BartoszPajB Offline
              BartoszPajB Offline
              BartoszPaj
              wrote on 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
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on 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

                BartoszPajB 1 Reply Last reply
                1
                • VRoninV VRonin

                  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();
                  
                  BartoszPajB Offline
                  BartoszPajB Offline
                  BartoszPaj
                  wrote on 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 last edited by
                    #8
                    This post is deleted!
                    1 Reply Last reply
                    -1
                    • BartoszPajB Offline
                      BartoszPajB Offline
                      BartoszPaj
                      wrote on 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