View OpenCV Mat in GDB, Code from: [Visualize in memory OpenCV image or matrix from GDB pretty printers](
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


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
  • Add the follow lines in ~/.gdbinit. The alias command is optional.
alias view = plot
alias imshow = plot
  • Usage
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
plot img_color
plot img_gray
  • view Mat in vector: if just use the follow command:
plot img_vec[0]
plot img_vec[1]

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

  • Install
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

Similar Projects to Show Image in GDB