Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access opencv matrix CV_32S element

Tags:

c++

opencv

matrix

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?

like image 380
Robert Kirchhoff Avatar asked Oct 08 '12 15:10

Robert Kirchhoff


People also ask

How to access matrix elements in OpenCV c++?

There are three common ways to access matrix elements in OpenCV C++. The . at template member function, the classical pointer access and iterators.

What is CV_32SC1?

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.

What is CV_64F?

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.

What is use of mat class in OpenCV?

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.


2 Answers

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>.

like image 132
Jav_Rock Avatar answered Oct 19 '22 22:10

Jav_Rock


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.

like image 24
CapelliC Avatar answered Oct 19 '22 22:10

CapelliC