Note that there are some explanatory texts on larger screens.

plurals
  1. POGDB cv::Mat python object issue when debugging a c++ program
    primarykey
    data
    text
    <p>When debugging a C++ OpenCV program, I'd like to see an image in my program under GDB, I mean I would like to visualize the data under GDB. Luckily I have: </p> <ol> <li>GDB with python support;</li> <li>I have installed python 2.7.4, numpy library, and opencv official release 2.4.4;</li> <li>I have installed the python interface file "cv2.pyd" to my python's site-packages folder.</li> </ol> <p>Now, I can run a pure python script which load and show an image. But my issue comes when I try to show an image from GDB. (The image is in my C++ program)</p> <pre><code>#include &lt;opencv/cv.h&gt; #include &lt;opencv/highgui.h&gt; using namespace cv; ... Mat orgImg = imread("1.jpg", CV_LOAD_IMAGE_GRAYSCALE); </code></pre> <p>Then I set a breakpoint after that, then GDB hit the breakpoint, I run such command in GDB's command line</p> <pre><code>source test.py </code></pre> <p>The test.py is a python script which try to show an image:</p> <pre><code>import gdb import cv2 import numpy class PlotterCommand(gdb.Command): def __init__(self): super(PlotterCommand, self).__init__("plot", gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL) def invoke(self, arg, from_tty): args = gdb.string_to_argv(arg) v = gdb.parse_and_eval(args[0]) t = v.type.strip_typedefs() print t a = numpy.asarray(v) cv2.namedWindow('debugger') cv2.imshow('debugger',a) cv2.waitKey(0) PlotterCommand() </code></pre> <p>After that, I just run the command</p> <pre><code>plot orgImg </code></pre> <p>But GDB get an error:</p> <pre><code>cv::Mat Python Exception &lt;type 'exceptions.TypeError'&gt; mat data type = 17 is not supported: Error occurred in Python command: mat data type = 17 is not supported Error occurred in Python command: mat data type = 17 is not supported </code></pre> <p>You see, the python object under GDB is "cv::Mat", but it can not to converted to a correct python object to show. Anyone can help me? Thanks.</p> <p><strong>EDIT:</strong> I try to create a more simple script which use cv (not cv2), but it still not work:</p> <pre><code>import gdb import cv2.cv as cv class PlotterCommand(gdb.Command): def __init__(self): super(PlotterCommand, self).__init__("plot", gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL) def invoke(self, arg, from_tty): args = gdb.string_to_argv(arg) v = gdb.parse_and_eval(args[0]) a = cv.CreateImageHeader((v['cols'],v['rows']), cv.IPL_DEPTH_8U, 1) cv.SetData(a, v['data']) cv.NamedWindow('debugger') cv.ShowImage('debugger', a) cv.WaitKey(0) PlotterCommand() </code></pre> <p>The above code does not work as the statement "cv.SetData(a, v['data'])" does not really do an buffer address assignment.</p> <p>The "v" is a representation of cv::Mat, which has the contents:</p> <pre><code>{flags = 1124024320, dims = 2, rows = 44, cols = 37, data = 0x3ef2d0 '\377' &lt;repeats 200 times&gt;..., refcount = 0x3ef92c, datastart = 0x3ef2d0 '\377' &lt;repeats 200 times&gt;..., dataend = 0x3ef92c "\001", datalimit = 0x3ef92c "\001", allocator = 0x0, size = {p = 0x22fe10}, step = {p = 0x22fe38, buf = {37, 1}}} </code></pre> <p>So, you see the "data" field is the raw buffer pointer, but I'm not sure how to transfer this gdb.Value to a python buffer type.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload