Element at location ( i, j, k ) in
three-dimensional float array M
To access a two-dimensional array, you can also extract a C-style pointer to a specific row of the array.
This is done with the ptr<>() template member function of cv::Mat. (Recall that the data in the array
is contiguous by row, thus accessing a specific column in this way would not make sense; we will see the
right way to do that shortly.) As with at<>(), ptr<>() is a template function instantiated with a type
name. It takes an integer argument indicating the row you wish a pointer to. The function returns a pointer
to the primitive type of which the array is constructed (i.e., if the array type is F32C3, the return value will
be of type float*). Thus, given a three-channel matrix mtx of type float, the construction
mtx.ptr<Vec3f>(3) would return a pointer to the first (floating-point) channel of the first element in
row 3 of mtx. This is generally the fastest way to access elements of an array,
18
because once you have the
pointer, you are right down there with the data.
There are thus two ways to get a pointer to the