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. [SOLVED] QImage exception
QtWS25 Last Chance

[SOLVED] QImage exception

Scheduled Pinned Locked Moved General and Desktop
qimageqlabel8bitgrayscale
20 Posts 3 Posters 7.9k 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.
  • SGaistS SGaist

    What image format are you using ?

    T Offline
    T Offline
    Tomzi
    wrote on last edited by
    #9

    @SGaist I wanted to have RGB32 for displaying because as I read Indexed_8 is not supported for display. So as you can see the error occurs when qt trying to convert from Indexed_8 to RGB32 (Of course the problem could be elsewhere). Basically the images are coming from a scientific camera which has a 12bit grayscale sensor but of course I down scaled the data to 8bit long before the control enters to this method

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

      You misunderstood the documentation, you can't draw into a QImage in that format, but you can display it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      0
      • SGaistS SGaist

        You misunderstood the documentation, you can't draw into a QImage in that format, but you can display it.

        T Offline
        T Offline
        Tomzi
        wrote on last edited by
        #11

        @SGaist Yes, you are right. That is what I tried for the first time but the images were displayed wrong in Indexed_8 format that is why I wanted to convert them to RGB32. But I don't think this is the source of my problem. I made 30 measurements again but without updating the QBytearray so the data was always the same and the previous error never came. In my opinion somehow my image data could be wrong sometimes and that is why the conversion fails.

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

          Did you find what triggers the error in your data ? Where does it come from ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply
          0
          • SGaistS SGaist

            Did you find what triggers the error in your data ? Where does it come from ?

            T Offline
            T Offline
            Tomzi
            wrote on last edited by
            #13

            @SGaist Not yet but It is strange that the error always came when the first frame arrives. I'll need some more time to debug.

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

              Only on the first frame ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              T 2 Replies Last reply
              0
              • SGaistS SGaist

                Only on the first frame ?

                T Offline
                T Offline
                Tomzi
                wrote on last edited by
                #15

                @SGaist Exactly. After the video streaming starts the error never shows up. I'll try to dump the first frame on the sender side and see what could be wrong with the data and so on. I don't think the problem caused by the QTcpSocket which transfers the frames.

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Only on the first frame ?

                  T Offline
                  T Offline
                  Tomzi
                  wrote on last edited by
                  #16

                  @SGaist Finally It seems I could solve the problem. The problem was that my frame receiver side had some issues that caused that unexpected frames could come before the previous transfer finished and that caused that during image conversion the QByteArray that holds the image data could change thus read access violations occurred. After I solved this issue the application have not crashed ever since (~50 measurements).

                  Thank you very much for your help! The conversations made me thinking more and finally this bug could be eliminated.

                  Cheers,
                  Tomzi

                  1 Reply Last reply
                  0
                  • SurajS Offline
                    SurajS Offline
                    Suraj
                    wrote on last edited by
                    #17

                    Sir, i am new to QT. So help me to fix this as i want to do the samething like you. I want to show live streming through webcamera...as i am using QTCreater 3.2.2 and QT 4.8 on fedora 20.
                    sir, i have done recording video and capturing video by using following code. I just call this code by using slots of "capture image" and "record a video":
                    // For Video:-
                    system("ffmpeg -f video4linux2 -i /dev/video0 -vcodec mpeg4 -b 12000k -r 25 -t 00:00:55 test12.avi");

                    //For image capture:-
                    system("fswebcam -s 15 --jpeg 95 --save /abasfc.jpeg");

                    Sir, i just want view this particular item on GUI (On QLabel or something) at the time of capturing image and recording video.. How to do that?
                    thanks in advance...

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

                      @Suraj, please don't hijack other users thread. You already have a thread opened here with answers

                      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
                      0
                      • SurajS Offline
                        SurajS Offline
                        Suraj
                        wrote on last edited by Suraj
                        #19

                        @SGaist ok sir. Sorry Sir. and thank you for guidance.

                        1 Reply Last reply
                        0
                        • SurajS Offline
                          SurajS Offline
                          Suraj
                          wrote on last edited by
                          #20

                          Thank all for your replay,
                          I solve my problem by using Phonon: :video player

                          Steps:-

                          i. Add Phonon::Video Player in ui file. I rename its programing name as "Video Player"
                          ii. Add one button in that ui file and go to that button slot and adding following code in it:-
                          // For getting system date and time for video name
                          time_t now = time(0);
                          struct tm tstruct;
                          char buf[80];
                          tstruct = *localtime(&now);

                          strftime(buf, sizeof(buf), "%d_%m_%y_%H_%M", &tstruct);
                          qDebug() << "Date and Time: "<<buf;
                          

                          // For getting static path where video will be stored
                          QString a = "/home/Working_QT/BackupErrorWorking/DeviceTestVersion1/video/";
                          a.append(buf);
                          a.append(".avi");
                          qDebug() << "a: "<<a;

                          // For giving comlete command as it is accepted as a QString and converted into char(Because konsole command is accepted only char it shows error so we convert it)
                          QString command = "ffmpeg -f video4linux2 -i /dev/video0 -vcodec mpeg4 -b 500k -r 25 -t 00:01:30 ";
                          command.append(a);
                          qDebug() << "Command: "<<command;
                          char x[200];
                          strcpy( x, command.toStdString().c_str());

                          // Commaand to sysytem
                          system(x);
                          qDebug() << "Command given to system to capture video and name it according to that particular date and time: "<<x;

                          // For playing video through Phonon VideoPlayer
                          qDebug("Before video recording display");
                          ui->VideoPlayer->play(Phonon::MediaSource(a));
                          qDebug("After video recording display");

                          iii. Included #include <time.h> // Required for giving video file name according to date and time
                          and #include <qdebug.h>
                          iv. Make changes in .pro file

                          QT += phonon

                          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