安装image watch
模块除了可以查看OpenCV,也可以查看自定义的图像格式。
可以参考的官方文档: https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/debugger/image-watch/image-watch-reference?view=vs-2015
可以从 C:\Users\USERNAME\AppData\Local\Microsoft\VisualStudio\17.0_6e3f40f8\Extensions\a14eewtt.z12
文件夹看到OpenCV
的配置文件 ImageWatchOpenCV.natvis
进行对照参考
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"><UIVisualizer ServiceId="{A452AFEA-3DF6-46BB-9177-C0B08F318025}" Id="1" MenuName="Add to Image Watch"/><!-- OpenCV cv::Mat --><Type Name="cv::Mat"><AlternativeType Name="cv::Mat_<*>"/><UIVisualizer ServiceId="{A452AFEA-3DF6-46BB-9177-C0B08F318025}" Id="1" /></Type><Type Name="cv::Mat"><AlternativeType Name="cv::Mat_<*>"/><DisplayString Condition="(flags&7)==0">{{UINT8, {((flags&0xfff)>>3)+1} x {cols} x {rows}}}</DisplayString><DisplayString Condition="(flags&7)==1">{{INT8, {((flags&0xfff)>>3)+1} x {cols} x {rows}}}</DisplayString><DisplayString Condition="(flags&7)==2">{{UINT16, {((flags&0xfff)>>3)+1} x {cols} x {rows}}}</DisplayString><DisplayString Condition="(flags&7)==3">{{INT16, {((flags&0xfff)>>3)+1} x {cols} x {rows}}}</DisplayString><DisplayString Condition="(flags&7)==4">{{INT32, {((flags&0xfff)>>3)+1} x {cols} x {rows}}}</DisplayString><DisplayString Condition="(flags&7)==5">{{FLOAT32, {((flags&0xfff)>>3)+1} x {cols} x {rows}}}</DisplayString><DisplayString Condition="(flags&7)==6">{{FLOAT64, {((flags&0xfff)>>3)+1} x {cols} x {rows}}}</DisplayString><DisplayString Condition="(flags&7)==7">{{USER, {((flags&0xfff)>>3)+1} x {cols} x {rows}}}</DisplayString><Expand><Synthetic Name="[type]" Condition="(flags&7)==0"><DisplayString>UINT8</DisplayString></Synthetic><Synthetic Name="[type]" Condition="(flags&7)==1"><DisplayString>INT8</DisplayString></Synthetic><Synthetic Name="[type]" Condition="(flags&7)==2"><DisplayString>UINT16</DisplayString></Synthetic><Synthetic Name="[type]" Condition="(flags&7)==3"><DisplayString>INT16</DisplayString></Synthetic><Synthetic Name="[type]" Condition="(flags&7)==4"><DisplayString>INT32</DisplayString></Synthetic><Synthetic Name="[type]" Condition="(flags&7)==5"><DisplayString>FLOAT32</DisplayString></Synthetic><Synthetic Name="[type]" Condition="(flags&7)==6"><DisplayString>FLOAT64</DisplayString></Synthetic><Item Name="[channels]">((flags&0xfff)>>3)+1</Item><Item Name="[width]">cols</Item><Item Name="[height]">rows</Item><Item Name="[data]">data</Item><Item Name="[stride]">step.p[0]</Item></Expand></Type>
</AutoVisualizer>
然后结合官方示例文档:
struct My8BitRGBImage
{ unsigned int ncols; unsigned int nrows; unsigned char* data;
};--------------------
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> <UIVisualizer ServiceId="{A452AFEA-3DF6-46BB-9177-C0B08F318025}" Id="1" MenuName="Add to Image Watch"/> <Type Name="My8BitRGBImage"> <UIVisualizer ServiceId="{A452AFEA-3DF6-46BB-9177-C0B08F318025}" Id="1" /> </Type> <Type Name="My8BitRGBImage"> <Expand> <Synthetic Name="[type]"> <DisplayString>UINT8</DisplayString> </Synthetic> <Synthetic Name="[channels]"> <DisplayString>RGB</DisplayString> </Synthetic> <Item Name="[width]">ncols</Item> <Item Name="[height]">nrows</Item> <Item Name="[data]">data</Item> <Item Name="[stride]">ncols*3</Item> </Expand> </Type>
</AutoVisualizer>
所以Type Name
设置为class
类名,图像内部需要设置 type|channels|width|height|data|stride
等参数。
如果要对模板类进行处理(模版类的中括号<(<
) >(*>
) &(&
)),需要针对类型去做type区分, 这里的Condition=
就相当于 switch-case
,type支持的数据类型从官方文档可以查到:
image Watch supports these channel types:
INT8, UINT8
INT16, UINT16
INT32
FLOAT16
FLOAT32
FLOAT64
编写好.natvis
并保存在
C:\Users\%USERNAME%\Documents\Visual Studio 2022\Visualizers
即可支持自定义图像格式。