View OpenCV Mat in GDB, Code from: Visualize in memory OpenCV image or matrix from GDB pretty printers
How to use
- Required packages: opencv, python wrapper for opencv (cv2), python, numpy
- Clone this repository
git clone email@example.com:beenfrog/gdb-opencv-viewer.git
- Add the follow lines in ~/.gdbinit. The alias command is optional.
source /FULL-PATH-OF-THE-FILE/cvplot.py alias view = plot alias imshow = plot
plot m, the m is an object of cv2::Mat view m, if you set alias view = plot imshow m, if you set alias imshow = plot
- debug and view image in gdb:
cd gdb-opencv-viewer mkdir Debug && cd Debug cmake -DCMAKE_BUILD_TYPE=Debug .. && make gdb ./viewer break 26 run plot img_color plot img_gray
- view Mat in vector: if just use the follow command:
plot img_vec plot img_vec
we will get:
Python Exception <class 'gdb.error'> Could not find operator.: Error occurred in Python command: Could not find operator.
and the right way to view the mat in vector is:
pvector img_vec plot $1 plot $2
See more in next section.
- NOTE: There may be some bugs with the imshow in python under GNU/Linux, which make you unable to close the image by click the "close" button on the dialog, but you can just click the image and press any key to close the image dialog.
It is easy to print the C++ STL elements such as vector, map with GDB evaluators/views/utilities
wget http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt cat dbinit_stl_views-1.03.txt >> ~/.gdbinit
- Demo (continue from the previous demo)
pvector vec pmap str_int_map char* int ... see more from the raw file: dbinit_stl_views-1.03.txt