Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Debug helper for visualizing images
QtWS25 Last Chance

Debug helper for visualizing images

Scheduled Pinned Locked Moved Qt Creator and other tools
8 Posts 4 Posters 5.2k 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.
  • D Offline
    D Offline
    dtmoodie
    wrote on 23 Oct 2014, 14:23 last edited by
    #1

    I'd like to make a debug visualizer for displaying image data similar to this product:
    https://visualstudiogallery.msdn.microsoft.com/e682d542-7ef3-402c-b857-bbfba714f78d
    Except for GDB in qt creator.
    Does anyone know if this is possible? All the examples I've seen show displaying custom text data in the same variable watch window, but I'm more interested in spawning a dialog that can display images.

    Is this possible with qtcreator? What kind of effort is required and where can I learn how to do this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andrep
      wrote on 3 Nov 2014, 21:16 last edited by
      #2

      It's possible. See e.g. http://blog.qt.digia.com/blog/2010/04/22/peek-and-poke-vol-3/. Syntax has changed a bit since then, but the feature is there.

      S 1 Reply Last reply 11 Dec 2019, 08:20
      1
      • D Offline
        D Offline
        dtmoodie
        wrote on 3 Nov 2014, 22:21 last edited by
        #3

        Excellent assistance, I've sorted out all the issues getting my debugger run.

        Now I'm just running into an issue getting it to actually dump the image and display it.
        Here is what I have so far:
        @
        #!/usr/bin/python
        from dumper import *

        def qform__cv__Mat():
        return "Normal,Displayed"

        def qdump__cv__Mat(d, value):
        cols = value["cols"]
        rows = value["rows"]
        flags = value["flags"]
        depth = flags & 7
        channels = 1 + (flags >> 3) & 63
        line_step = value['step']['p'][0]

        if depth == 0:
            d.putValue("(%dx%dx%d) CV_8U" %(rows,cols,channels))
        if depth == 1:
            d.putValue("(%dx%dx%d) CV_8S" %(rows,cols,channels))
        if depth == 2:
            d.putValue("(%dx%dx%d) CV_16U" %(rows,cols,channels))
        
        if depth == 3:
            d.putValue("(%dx%dx%d) CV_16S" %(rows,cols,channels))
        
        if depth == 4:
            d.putValue("(%dx%dx%d) CV_32S" %(rows,cols,channels))
        
        if depth == 5:
            d.putValue("(%dx%dx%d) CV_32F" %(rows,cols,channels))
        
        if depth == 6:
            d.putValue("(%dx%dx%d) CV_64F" %(rows,cols,channels))
        
        line_step = value['step']['p'][0]
        data_start = value['data']
        #data_start = d.extractPointer(d.addressOf(value['datatstart']))
        data_end = value['dataend']
        nbytes = data_end - data_start
        nbytes = rows * cols * channels
        d.putNumChild(1)
        padding = line_step - cols * channels
        bits = d.extractPointer(data_start)
        with Children(d):
           d.putSubItem("Data start", data_start)
           d.putSubItem("Rows", rows)
           d.putSubItem("Cols", cols)
           d.putSubItem("Channels", channels)
           d.putSubItem("Depth", depth)
           d.putSubItem("Num Bytes", nbytes)
           d.putSubItem("Data end", data_end)
           d.putSubItem("Row Step", line_step)
           d.putSubItem("Padding", padding)
           with SubItem(d, "data"):
               d.putValue("0x%x" % bits)
               d.putNumChild(0)
               d.putType("void *")
        format = d.currentItemFormat()
        if format == 1:
            d.putDisplay(StopDisplay)
        if format == 2:
            #file = tempfile.mkstemp(prefix="gdbpy_")
            #filename = file[1].replace("\\", "\\\\")
            #gdb.execute("dump binary memory %s %s %s" % (filename, bits, bits + nbytes))
            #d.putDisplay(DisplayImageFile, " %d %d %d %d %s" % (cols, rows, nbytes, channels, filename))
            d.putField("editformat", DisplayImageData)
            d.put('editvalue="')
            d.put('xxxx' % (cols, rows, nbytes, channels))
            d.put(d.readMemory(bits,nbytes))
            d.put('",')
        

        @
        This dumps all the requested information nicely, but the problem lies in actually viewing the image now.
        In a simple test program, I make a QImage and then load a cv::Mat, I can then view the QImage through change local display format > Displayed. This option however doesn't exist for the cv::Mat.

        Here is a section of test code:
        @
        QImage im(QSize(200, 200), QImage::Format_RGB32);
        im.fill(QColor(200, 10, 30).rgba());
        QPainter p;
        p.begin(&im);
        p.setPen(QPen(Qt::black, 5.0, Qt::SolidLine, Qt::RoundCap));
        p.drawEllipse(20, 20, 160, 160);
        p.drawArc(70, 115, 60, 30, 200 * 16, 140 * 16);
        p.setBrush(Qt::black);
        p.drawEllipse(65, 70, 15, 15);
        p.drawEllipse(120, 70, 15, 15);
        p.end();
        ui->setupUi(this);
        std::string path = "/home/dan/Dropbox/Photos/x0ml8.png";
        if(path.size() == 0) return;
        cv::Mat img = cv::imread(path);
        cv::imshow("test",img);
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andrep
          wrote on 4 Nov 2014, 18:06 last edited by
          #4

          The 'xxxx' in the "d.put('xxxx' % (cols, rows, nbytes, channels))" line should be 'xxxx' - the exact format is important.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andrep
            wrote on 4 Nov 2014, 18:07 last edited by
            #5

            Ok... something here eats percent signs. So I guess you did it correctly initially ( 'percent' 'zero' 'eight' 'x' , repeated four times)

            Your problem might be 'execfile', which is Python 2.x only, and a GDB build with Python 3.x.

            The easiest solution for that would be using a recent Qt Creator build, and enter the path the file with your dumpers in Tools->Options, Debugger, GDB tab, "Extra Debugging Helpers"

            1 Reply Last reply
            1
            • D Offline
              D Offline
              dtmoodie
              wrote on 4 Nov 2014, 18:13 last edited by
              #6

              Hi Andre,
              Thanks again for helping me with this. Here's a link to the source in a github page.
              https://github.com/dtmoodie/GDB-ImageWatch/blob/master/qt-imageWatch/cvTypes.py

              The 'data' field is stored as an "unsigned char *" which is the starting point of where the memory dump should occur. Unfortunately I think I'm extracting this incorrectly, but I don't know how I should change it. I've looked at a few examples in the boost library dumpers and from tutorials, but none have done anything.

              1 Reply Last reply
              0
              • A andrep
                3 Nov 2014, 21:16

                It's possible. See e.g. http://blog.qt.digia.com/blog/2010/04/22/peek-and-poke-vol-3/. Syntax has changed a bit since then, but the feature is there.

                S Offline
                S Offline
                SachinBhat
                wrote on 11 Dec 2019, 08:20 last edited by
                #7

                @andrep Could you please repost the link. This does not exist

                aha_1980A 1 Reply Last reply 11 Dec 2019, 08:37
                0
                • S SachinBhat
                  11 Dec 2019, 08:20

                  @andrep Could you please repost the link. This does not exist

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 11 Dec 2019, 08:37 last edited by
                  #8

                  Hi @SachinBhat,

                  you mean this one: https://www.qt.io/blog/2010/04/22/peek-and-poke-vol-3 ?

                  Regards

                  Qt has to stay free or it will die.

                  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