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.
  • T Offline
    T Offline
    Tomzi
    wrote on last edited by Tomzi
    #1

    Dear Members,

    I am trying to display 8bit grayscale images on a QLabel to provide live video stream from a scientific camera.
    I am getting the same error time to time, sometimes the code runs correctly for 5 times in a row but then the attached
    error came(also you can see part of the code from where the exception comes) and I really stucked in find out why.

    screenshot link

    I am writing a multi threading GUI application so my first idea was it must be some
    simultanious access problem to resources but now I am not sure.

    Thank you in advance for you help!

    Best regards,
    Tamás

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

      Hi and welcome to devnet,

      There's no link to the screen shot. In between and since you are doing multithreading with QImage, you could check the Mandelbrot example to see how they do the communication.

      Hope it helps

      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

        Hi and welcome to devnet,

        There's no link to the screen shot. In between and since you are doing multithreading with QImage, you could check the Mandelbrot example to see how they do the communication.

        Hope it helps

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

        @SGaist Hi and thank you for you answer. The link is now working, I'll check the mandelbrot example and see if I can get the answer for my question.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tomzi
          wrote on last edited by
          #4

          I have checked the mandelbrot example but I don't think I have simultanious access problems because I also tried to do the image processing sequential so I defined flags which tells when the QBytearray is ready so it's content is only changing when image processing is finished. If you check the screenshot you can see the exception comes from deep down but I don't know why.

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

            Why are you allocating the QImage on the heap ?

            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

              Why are you allocating the QImage on the heap ?

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

              @SGaist Because I didn't want to have static resources because the whole software could consume quite big amount of resources because it handles a 10 fast camera system and each camera could produce 20Hz live video stream over the network. Do you think the problem comes from dynamic allocation?

              1 Reply Last reply
              0
              • SGaistS SGaist

                Why are you allocating the QImage on the heap ?

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

                @SGaist I've just tested it with allocating QImage on the stack but the same error occurs after nearly the same measurement (8-10)
                I also tried to check if the QImage is not valid but it did not helped because it seems that it is valid always.

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

                  What image format are you using ?

                  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

                    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