Skip to content

Commit 267fdc4

Browse files
committed
Add a note about cxx11 range-based loop in Mat_ documentation
1 parent e5aa213 commit 267fdc4

File tree

1 file changed

+15
-4
lines changed
  • modules/core/include/opencv2/core

1 file changed

+15
-4
lines changed

modules/core/include/opencv2/core/mat.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ class CV_EXPORTS Mat
20632063

20642064
/** @brief Template matrix class derived from Mat
20652065
2066-
@code
2066+
@code{.cpp}
20672067
template<typename _Tp> class Mat_ : public Mat
20682068
{
20692069
public:
@@ -2075,7 +2075,7 @@ class CV_EXPORTS Mat
20752075
The class `Mat_<_Tp>` is a *thin* template wrapper on top of the Mat class. It does not have any
20762076
extra data fields. Nor this class nor Mat has any virtual methods. Thus, references or pointers to
20772077
these two classes can be freely but carefully converted one to another. For example:
2078-
@code
2078+
@code{.cpp}
20792079
// create a 100x100 8-bit matrix
20802080
Mat M(100,100,CV_8U);
20812081
// this will be compiled fine. no any data conversion will be done.
@@ -2087,7 +2087,7 @@ While Mat is sufficient in most cases, Mat_ can be more convenient if you use a
20872087
access operations and if you know matrix type at the compilation time. Note that
20882088
`Mat::at(int y,int x)` and `Mat_::operator()(int y,int x)` do absolutely the same
20892089
and run at the same speed, but the latter is certainly shorter:
2090-
@code
2090+
@code{.cpp}
20912091
Mat_<double> M(20,20);
20922092
for(int i = 0; i < M.rows; i++)
20932093
for(int j = 0; j < M.cols; j++)
@@ -2097,7 +2097,7 @@ and run at the same speed, but the latter is certainly shorter:
20972097
cout << E.at<double>(0,0)/E.at<double>(M.rows-1,0);
20982098
@endcode
20992099
To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter:
2100-
@code
2100+
@code{.cpp}
21012101
// allocate a 320x240 color image and fill it with green (in RGB space)
21022102
Mat_<Vec3b> img(240, 320, Vec3b(0,255,0));
21032103
// now draw a diagonal white line
@@ -2107,6 +2107,17 @@ To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter:
21072107
for(int i = 0; i < img.rows; i++)
21082108
for(int j = 0; j < img.cols; j++)
21092109
img(i,j)[2] ^= (uchar)(i ^ j);
2110+
@endcode
2111+
Mat_ is fully compatible with C++11 range-based for loop. For example such loop
2112+
can be used to safely apply look-up table:
2113+
@code{.cpp}
2114+
void applyTable(Mat_<uchar>& I, const uchar* const table)
2115+
{
2116+
for(auto& pixel : I)
2117+
{
2118+
pixel = table[pixel];
2119+
}
2120+
}
21102121
@endcode
21112122
*/
21122123
template<typename _Tp> class Mat_ : public Mat

0 commit comments

Comments
 (0)