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. Load the liveview image from CanonSDK to QLabel
Forum Updated to NodeBB v4.3 + New Features

Load the liveview image from CanonSDK to QLabel

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 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.
  • K Offline
    K Offline
    Khairul Ikhwan
    wrote on last edited by
    #1

    Hi and good day,

    I would like to show the liveview image from Canon SDK to QLabel. (I was using QLabel all this while to show the image and it seems fine)

    Or should I use different widget instead?

    Camera::requestDownloadEvfData(QImage& img)

    I was able to save in the folder using img.save method, however, I am not able to set currentImage (QLabel) with the error QPixmap::scaled: Pixmap is a null pixmap.

    Below is the following code I use:

    void CameraView::LoadLiveViewImage(QImage& liveViewImage)
    {
    currentImage->setPixmap(QPixmap::fromImage(liveViewImage).scaled(ui->baseLayout->cellRect(1, 0).width(), ui->baseLayout->cellRect(1, 0).height(), Qt::KeepAspectRatio));
    }

    Probably I missed some steps instead?

    Thank you!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      QLabel is ok to use as fast way to display a pixmap. For more features, a custom widget with paintEvent is better.
      The error you get ( Pixmap is a null pixmap) sounds like is returning a NULL Pixmap

      is liveViewImage ok ?
      i would save img to file and look at it.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Khairul Ikhwan
        wrote on last edited by
        #3

        Hi,

        thanks for the reply, do you mean that I have to create custom widget in order for me to have paintEvent?

        It seems that occasionally, I will get null pixmap from requestDownloadEvfData, not sure though but i will add the checking on that.

        As you mentioned, QLabel is fine to use it, can I do looping on it? E.g.:

        do
        {
            QImage img;
            if ( cam != NULL && cam->hasOpenSession() && cam->isLiveViewing())
            {
                cam->requestDownloadEvfData(img);        
                cameraView->LoadLiveViewImage(img);
            }
            else
                break;
        } while (true);
        

        Yes, liveViewImage is okay, I have tried to use liveViewImage.save and it returns true. (Also from the directory, it indeed saves the image file).

        mrjjM 1 Reply Last reply
        0
        • K Khairul Ikhwan

          Hi,

          thanks for the reply, do you mean that I have to create custom widget in order for me to have paintEvent?

          It seems that occasionally, I will get null pixmap from requestDownloadEvfData, not sure though but i will add the checking on that.

          As you mentioned, QLabel is fine to use it, can I do looping on it? E.g.:

          do
          {
              QImage img;
              if ( cam != NULL && cam->hasOpenSession() && cam->isLiveViewing())
              {
                  cam->requestDownloadEvfData(img);        
                  cameraView->LoadLiveViewImage(img);
              }
              else
                  break;
          } while (true);
          

          Yes, liveViewImage is okay, I have tried to use liveViewImage.save and it returns true. (Also from the directory, it indeed saves the image file).

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Khairul-Ikhwan
          Hi
          Sort of, if u create a custom widget, you can implement your own painting. Say if you needed some overlay or
          something like that.

          Looping in a GUI application is not a good idea as it will strangulate its event loop.
          It would be better using a QTimer and it its slot , just do the code without looping.
          (the timer will be the non blocking looping)

          1 Reply Last reply
          2
          • K Offline
            K Offline
            Khairul Ikhwan
            wrote on last edited by
            #5

            Hi,

            noted on that, I think for now I will try to implement the liveview feature using QLabel first.

            Thanks for the advices, I will check on QTimer, but as of now, it seems that I can't set the QLabel without saving into the local path first.

            currentImage->setPixmap(QPixmap::fromImage(testImage).scaled(ui->baseLayout->cellRect(1, 0).width(), ui->baseLayout->cellRect(1, 0).height(), Qt::KeepAspectRatio));

            Which means I can't feed liveViewImage into fromImage function, as it will not show any image at all.

            There's no compilation/runtime error though, do you think I have done in wrong way?

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              The requestDownloadEvfData seems to be part of the SDK?
              I cant tell where/why it goes wrong. you need to inspect values. i think :)
              What does QImage::format() say?
              QImage img;
              Camera::requestDownloadEvfData(img)
              qDebug() << img.format() << " null:" << img.QImage::isNull();
              Also for this. you are 100% sure the cellRect provides correct values?
              QPixmap::fromImage(testImage).scaled(ui->baseLayout->cellRect(1, 0).width(), ui->baseLayout->cellRect(1, 0).height(), Qt::KeepAspectRatio)

              1 Reply Last reply
              2
              • K Offline
                K Offline
                Khairul Ikhwan
                wrote on last edited by
                #7

                Hi,

                yes, requestDownloadEvfData is the wrapper function for the SDK, I will try to check on it why it's sometimes returning the odd value :D

                as for the QImage:format, it returns:
                4 null: false

                So I guess the wrong thing here goes when initializing the QPixmap, and yes, after debugging again, cellRect does not provide the value(and it's null instead).

                I am able to show the image by calling :
                currentImage->setPixmap(QPixmap::fromImage(liveViewImage));

                without scaling it yet.

                Just my thought, as for the timer setup, since I will need to show liveview from the camera, would making it as little as possible be fine to the application? Just in terms of memory handling etc. :/

                for example; mLiveViewTimer.setInterval(10);

                Anyhow, thank you for the great advices to check things!

                mrjjM 1 Reply Last reply
                0
                • K Khairul Ikhwan

                  Hi,

                  yes, requestDownloadEvfData is the wrapper function for the SDK, I will try to check on it why it's sometimes returning the odd value :D

                  as for the QImage:format, it returns:
                  4 null: false

                  So I guess the wrong thing here goes when initializing the QPixmap, and yes, after debugging again, cellRect does not provide the value(and it's null instead).

                  I am able to show the image by calling :
                  currentImage->setPixmap(QPixmap::fromImage(liveViewImage));

                  without scaling it yet.

                  Just my thought, as for the timer setup, since I will need to show liveview from the camera, would making it as little as possible be fine to the application? Just in terms of memory handling etc. :/

                  for example; mLiveViewTimer.setInterval(10);

                  Anyhow, thank you for the great advices to check things!

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Khairul-Ikhwan
                  Hi
                  It seems it sometimes returns invalid image so there must be something there.
                  If you only capture 1 image and not store multiple (as video) its not so likely
                  that memory will be an issue. Making it smaller will most likely allow you to capture faster and
                  draw it.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Khairul Ikhwan
                    wrote on last edited by
                    #9

                    @mrjj ,
                    Hi,
                    noted on that, I will check there too.

                    As of right now, I have implemented the timer (10), and QLabel seems to be working now, just that there's gap in between the images that seems to look like a glitch (like sudden white screen).

                    mrjjM 1 Reply Last reply
                    0
                    • K Khairul Ikhwan

                      @mrjj ,
                      Hi,
                      noted on that, I will check there too.

                      As of right now, I have implemented the timer (10), and QLabel seems to be working now, just that there's gap in between the images that seems to look like a glitch (like sudden white screen).

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Khairul-Ikhwan
                      Hi, make sure you dont go too fast as the camera might have a min capture time.
                      A white image sounds a bit odd, as it sounds like its being filled but no camera image is
                      applied.

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        Khairul Ikhwan
                        wrote on last edited by
                        #11

                        @mrjj ,
                        Hi, noted on that, I think for now the interval for the timer is sufficient. I will probably need to check again on the image as it's not reproducible sometimes.

                        Anyhow, the main issue has been resolved. Thank you so much for the help!

                        1 Reply Last reply
                        1

                        • Login

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