Debug_in_Visual_Studio_using_NativeViewer - alalek/opencv GitHub Wiki
This article is about debugging native C++ projects using Visual Studio 2010.
Quick links: NativeViewer at SourceForge and at Visual Studio Gallery.
We all spend a lot of time during debug of our projects. In Visual Studio we have such nice tools as “Watches” window and debugger tool-tips in the editor. These allow us to observe the values of variables determining state of our program.
But what about images? How do we observe image content during debug? Usually the functions like imwrite
or imshow
are injected into code to spy over a certain image. But this approach has an obvious drawback: it requires a program rebuild to observe an image for which we don’t have such instructions. In this article a tool named NativeViewer is described, which allows to view an image content in the same way the usual variables are sought. See the screenshot of the thumbnail image displayed during debug in Visual Studio 2010.
NativeViewer is a Visual Studio 2010 extension in the form of VSIX package. Check the links at the top of this page to find downloads. Don’t forget to go through the Quick Start Guide before using. The project page at SourceForge is the homepage of the extension. Check it for the newer versions or the updated documentation.
NativeViewer only works within the following conditions:
- Native C++ code
- Visual Studio 2010
- Both x86 or x64 target platforms
- Images of the
cv::Mat
type withCV_TYPE
equal toCV_8UC1
orCV_8UC3
- Colored images format
BGR
orRGB
The first constraint is by design. The others might be relaxed in the future versions.
To get the underlying image content, NativeViewer uses the Debugging Expression Evaluator Add-In. It exploits the autoexp.dat
file located in the Visual Studio directory and used for formatting debugger expansion strings. E.g. this file is the reason why you see the std::vector
content so well-formatted. The syntax of the autoexp.dat
allows calling an external library to format an expansion string. The access to the value of a formatted variable is provided to this library. The rest is paperwork.
This approach has a bunch of drawbacks, so if you know the better solution – please, share it using the SourgeForge discussions or in any other appropriate way.