简体   繁体   中英

How to find out what type to use for OpenCV .at function in C++?

Is there a simple reliable way to find out what equivalent type I should use for the .at function for a Mat of a given CV type?

For example, how can I tell that the blanks should be filled with ushort , float and Vec3b ?

Mat mat1(1, 2, CV_16UC1, 12345);
std::cout << mat1.at<___>(0, 1) << "\n";
Mat mat2(1, 2, CV_32FC1, 67.89);
std::cout << mat2.at<___>(0, 1) << "\n";
Mat mat3(1, 2, CV_8UC3, Scalar(65, 66, 67));
std::cout << mat3.at<___>(0, 1)[2] << "\n";

Using data from

I constructed the following table:

        C1      C2     C3     C4     C6 (not sure whether C6 subtype exists as a macro)
CV_8U   uchar   Vec2b  Vec3b  Vec4b
CV_8S   char    -       
CV_16U  ushort  -
CV_16S  short   Vec2s  Vec3s  Vec4s
CV_32S  int     Vec2i  Vec3i  Vec4i
CV_32F  float   Vec2f  Vec3f  Vec4f  Vec6f
CV_64F  double  Vec2d  Vec3d  Vec4d  Vec6d

with uchar == unsigned char and ushort == unsigned short

for missing types you could create your own typedef if you want to:

typedef Vec<ushort, 2> Vec2us;

or you just access it with am type of same size ( Vec2s ) and convert it afterwards

But in the end I think understanding what the format means (32 bit floating point number with 3 channels = 3 float values per matrix element) if much better than looking at a table...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM