When debugging a C ++ OpenCV program, I would like to see the image in my program under GDB, I mean that I would like to visualize the data in GDB. Fortunately, I have:
- GDB with python support;
- I installed python 2.7.4, the numpy library and the official version of opencv 2.4.4;
- I installed the python interface file "cv2.pyd" in the python site-packages folder.
Now I can run a pure python script that loads and displays the image. But my problem arises when I try to display an image from GDB. (The image is in my C ++ program)
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv;
...
Mat orgImg = imread("1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Then I set a breakpoint after that, then GDB hit a breakpoint, I ran such a command on the GDB command line
source test.py
Test.py python script, :
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()
plot orgImg
GDB :
cv::Mat
Python Exception <type 'exceptions.TypeError'> 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
, python GDB "cv:: Mat", python . - ? .
EDIT:
script, cv (not cv2), :
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()
cv.SetData(a, v ['data']) " .
"v" cv:: Mat, :
{flags = 1124024320, dims = 2, rows = 44, cols = 37, data = 0x3ef2d0 '\377' <repeats 200 times>..., refcount = 0x3ef92c, datastart = 0x3ef2d0 '\377' <repeats 200 times>..., dataend = 0x3ef92c "\001", datalimit = 0x3ef92c "\001", allocator = 0x0, size = {p = 0x22fe10}, step = {p = 0x22fe38, buf = {37, 1}}}
, , , , gdb.Value python.