Access opencv matrix CV_32S element
20,814
Solution 1
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>
.
Solution 2
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.
Author by
Robert Kirchhoff
Updated on July 09, 2022Comments
-
Robert Kirchhoff almost 2 years
If I have a matrix of type
CV_32SC1
, what typename should I use in functionMat::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?
-
Mick MacCallum over 11 yearsPlease actually read the reviews you are clicking approve on.
-
Martin R. almost 8 yearsIn this case I would prefer <int32_t> to <int>, as the C++ standard does not specify the bit-size of integral types.
-
greggo about 7 yearsNot quite true. with
at<T>
, the addressing in x direction is based entirely on the size of T . If your matrix is CV_8UC3, thenX.at<cv::Vec3b>(0,2)
will get you the third pixel on the first row; butX.at<uint8_t>(0,2*3+1)
will give you the second channel of the same pixel (i.e the same byte asX.at<cv::Vec3b>(0,2)[1]
Because of this, the pitch in x direction is based on a compile-time constantsizeof(T)
rather than on a value calculated from the type stored in the Mat object, which makes a considerable difference in performance. It also supports 'flat' view of multi-channel arrs. -
greggo about 7 yearsThere is no CV_32U* type. But you can still use
X.at<uint32_t>(i,j)
if your CV_32SC1 array actually contains unsigned values.