![]() |
OpenCV 4.12.0
开源计算机视觉
|
| 原始作者 | 马克西姆·沙布宁 |
| 兼容性 | OpenCV >= 3.0 |
Doxygen 是一个文档生成系统,具有许多强大的功能,例如
OpenCV 库的现有文档已转换为 Doxygen 格式。
请查阅官方下载和安装页面。一些 Linux 发行版也可能提供 Doxygen 软件包。
整个文档从许多不同的地方收集:
以下方案表示 opencv 仓库的常见文档位置:
自 3.0 版本起,所有新模块都放置在 opencv_contrib 仓库中,其布局略有不同:
要为函数、类和其他实体添加文档,只需在其定义之前插入特殊注释,如下所示:
/** @brief Calculates the exponent of every array element.
The function exp calculates the exponent of every element of the input array:
\f[ \texttt{dst} [I] = e^{ src(I) } \f]
The maximum relative error is about 7e-6 for single-precision input and less than 1e-10 for
double-precision input. Currently, the function converts denormalized values to zeros on output.
Special values (NaN, Inf) are not handled.
@param src input array.
@param dst output array of the same size and type as src.
@sa log , cartToPolar , polarToCart , phase , pow , sqrt , magnitude
*/
CV_EXPORTS_W void exp(InputArray src, OutputArray dst);
您可以看到:
/** ... */
brief 表示接下来的段落是简要描述@brief
f[ 和 f] 命令之间的 TeX 公式\f[ ... \f]
param 表示接下来的词是参数名称,其后的文本是参数描述;所有参数都放在一个列表中@param
sa 开始一个“另请参见”段落,其中包含对某些类、方法、页面或 URL 的引用。@sa
生成的引用项如下所示: 
“更多...”链接将您带到函数文档: 
可以使用不同的注释语法来表示单行短注释:
//! type of line
enum LineTypes {
FILLED = -1,
LINE_4 = 4, //!< 4-connected line
LINE_8 = 8, //!< 8-connected line
LINE_AA = 16 //!< antialiased line
};
在这里
//!
< 表示此注释位于被文档化实体之后//!<
生成的文档块如下所示: 
Doxygen 命令以 @ 或 \ 符号开头
@brief ... or \brief ...
Doxygen 注释可以有不同的形式
C-style: /** ... */ or /*! ... */ C++-style //! ... or /// ... Lines can start with '*': /** * ... * ... */ Can be placed after documented entity: //!< ... /**< ... */
要结束段落,请插入空行或任何开始新段落的命令
@brief brief description paragraph brief continues new paragraph @note new note paragraph note paragraph continues another paragraph paragraph continues
页面、锚点、组和其他命名实体在整个项目中应具有唯一的名称。最好以模块名称作为这些标识符的前缀。
@page core_explanation_1 Usage explanation @defgroup imgproc_transform Image transformations @anchor mymodule_interesting_note
Doxygen 支持带有一些扩展的 Markdown 格式。下面描述了简短的语法参考,详情请访问 Markdown 支持。
Bulleted: - item1 - item2 Numbered: 1. item1 2. item2 or -# item1 -# item2
_italic_ __bold__ use html in complex cases: <em>"path/to/file"</em>
explicit link: [OpenCV main site](https://opencv.ac.cn) automatic links: <https://opencv.ac.cn> or even: https://opencv.ac.cn

Level1 ====== Level2 ------ ### Level3 #### Level4
您可以为任何标题分配一个唯一标识符,以便从其他地方引用它。
Header {#some_unique_identifier}
------
...
See @ref some_unique_identifier for details
每个页面开头都应有一个额外的 Level1 标题,包含页面标题和标识符
Writing documentation for OpenCV {#tutorial_documentation}
================================
Doxygen 文档中的示例
First Header | Second Header ------------- | ------------- Content Cell | Content Cell Content Cell | Content Cell
这里描述了最常用的 Doxygen 命令,并附有简短示例。有关可用命令的完整列表和详细描述,请访问 命令参考。
param - 函数参数的描述。
多个相邻语句合并为一个列表。如果在实际函数签名中未找到具有此名称的参数,Doxygen 将生成警告。函数可以 没有 文档化的参数,也可以 所有 参数都应被文档化。
ref 命令引用。它只能在页面中使用。ref - 对命名部分、页面或锚点的显式引用。
如果找不到此类实体,Doxygen 将生成警告。此命令有一个可选参数 - 链接文本。
Doxygen 还会自动生成一些链接:如果文本包含在已文档化实体中可以找到的词,则会生成引用。可以通过在词前添加 % 符号来禁用此功能。
Explicit reference: @ref MyClass Explicit named reference: @ref example_page "Example page" Implicit reference: cv::abc::MyClass1 or just MyClass1 Disable implicit reference: %MyClass1
f - 公式
内联公式由 f$ 命令限定
\f$ ... \f$
块级公式由 f[ 和 f] 命令限定
\f[ ... \f]
要在文档中将某些文本标记为代码,使用 code 和 endcode 命令。
@code
float val = img.at<float>(borderInterpolate(100, img.rows, cv::BORDER_REFLECT_101),
borderInterpolate(-5, img.cols, cv::BORDER_WRAP));
@endcode
语法将根据当前解析的文件类型(.hpp 为 C++,.h 为 C)进行高亮显示,或者您可以在大括号中手动指定它
@code{.xml}
要将整个示例文件包含到文档中,使用 include 和 includelineno 命令。文件会在常见的示例位置中搜索,因此您只需指定其名称或路径的简短部分。includelineno 版本还会显示行号,但由于包含行号,因此会阻止复制粘贴。
@include samples/cpp/test.cpp
如果要包含现有示例文件的某些部分,请使用 snippet 命令。
首先,使用特殊的 Doxygen 注释标记文件中的所需部分
//! [var_init] int a = 0; //! [var_init]
然后将此片段包含到文档中
@snippet samples/cpp/test.cpp var_init
切换按钮用于显示选定的配置(例如,编程语言、操作系统、IDE)。
要在文档中使用这些按钮,需要使用 add_toggle 和 end_toggle 命令。
add_toggle 命令可以是:
示例
@add_toggle{Button Name}
text / code / doxygen commands
@end_toggle
例如,将切换按钮与文本和代码片段一起使用
### Buttons Example @add_toggle_cpp Text for C++ button @snippet samples/cpp/tutorial_code/introduction/documentation/documentation.cpp hello_world @end_toggle @add_toggle_java Text for Java button @snippet samples/java/tutorial_code/introduction/documentation/Documentation.java hello_world @end_toggle @add_toggle_python Text for Python button @snippet samples/python/tutorial_code/introduction/documentation/documentation.py hello_world @end_toggle
结果如下所示:
如您所见,按钮会自动添加到上一个标题下方。
所有代码实体都应放入代表 OpenCV 模块及其内部结构的命名组中,因此每个模块都应与一个同名组相关联。定义组和子组的好地方是该模块的主头文件:"<module>/include/opencv2/<module>.hpp"。
/**
@defgroup mymodule My great module
optional description
@{
@defgroup mymodule_basic Basic operations
optional description
@defgroup mymodule_experimental Experimental operations
optional description
@}
*/
要将类和函数放入特定组中,只需在其文档中添加 ingroup 命令,或者用 addtogroup 命令包装整个代码块。
/** @brief Example function
@ingroup mymodule
*/
or
/**
@addtogroup mymodule_experimental
@{
*/
... several functions, classes or enumerations here
/**
@}
*/
使用 cite 命令插入对参考文献页面中列出的相关出版物的引用。
首先,将出版物 BibTeX 记录添加到 "<opencv>/doc/opencv.bib" 或 "<opencv_contrib>/modules/<module>/doc/<module>.bib" 文件中。
@ARTICLE{Bradski98,
author = {Bradski, Gary R},
title = {Computer vision face tracking for use in a perceptual user interface},
year = {1998},
publisher = {Citeseer}
}
然后使用 cite 命令进行引用
@cite Bradski98

本节中描述的步骤可在编写文档时用作检查清单。并非所有步骤都必须按相同顺序进行,但有些步骤确实依赖于之前的步骤。当然,这些步骤只是基本指南,总有发挥创造力的空间。
编写示例应用程序,应足够简单以便初级开发人员理解。言简意赅,编写描述性注释,不要试图避免所有可能的运行时错误或制作通用工具。您的目标是阐明想法。而且它应该适合一个源文件!
如果您想将此文件中的代码块插入到教程中,请使用特殊的 Doxygen 注释标记它们(参见此处)。
如果您想用多种编程语言编写教程,请使用切换按钮来实现替代注释和代码(参见此处)。
收集应用程序运行结果。可以是“前后”对比图片、表示性能的数字,甚至是视频。
以适当的格式保存,以便稍后在教程中使用:
-DBUILD_EXAMPLES=ON 选项时,它能与 OpenCV 库一起编译。@prev_tutorial{identifier}
@next_tutorial{identifier} @prev_tutorial{#tutorial_documentation} 正确@prev_tutorial{tutorial_documentation} 描述您的结果,插入之前添加的图片或其他结果。
要添加 YouTube 视频,例如 www.youtube.com/watch?v= ViPN810E0SU,请使用 youtube{视频 ID}
@youtube{ViPN810E0SU}将新创建的教程添加到相应的目录中。只需找到包含所需表格的 "table_of_content_*.markdown" 文件,并以与现有记录类似的方式在其中添加新记录。
它只是一个列表项,带有特殊的 subpage 命令,该命令将您的页面标记为子页面并将其放入现有页面层次结构中。另请注意列表项缩进、段落之间的空行和特殊的 斜体 标记。