If I have a matrix of type CV_32SC1
, what typename should I use in function Mat::at
?
e.g.
Mat X; // for example eye matrix of size 10,10,and type CV_32SC1
X.at<??????>(1,1)=5;
How can I find the typename for other matrix types?
There are three common ways to access matrix elements in OpenCV C++. The . at template member function, the classical pointer access and iterators.
CV_32SC1 is a 1 Channel of Signed 32 bit integer, then I think that X.at<int>() should do. Mat already 'knows' how to address a pixel, the type just cast the bits to the C++ value you require for the expression evaluation. I found here some explanation about the notation.
CV_64F is the same as CV_64FC1 . So if you need just 2D matrix (i.e. single channeled) you can just use CV_64F. EDIT. More generally, type name of a Mat object consists of several parts.
The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.
The general rule for Matrices typenames in OpenCV is:
CV_<bit_depth>(S|U|F)C<number_of_channels>
S = Signed integer
U = Unsigned integer
F = Float
So depending on which one of the previous letters (S,U,F) you have, you will be casting <int>
, <unsigned integer>
or <float>
.
CV_32SC1 is a 1 Channel of Signed 32 bit integer, then I think that X.at<int>()
should do.
Mat already 'knows' how to address a pixel, the type just cast the bits to the C++ value you require for the expression evaluation.
I found here some explanation about the notation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With