[英]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? 是否有一种简单可靠的方法来找出我应该为给定CV类型的Mat使用.at函数的等效类型?
For example, how can I tell that the blanks should be filled with ushort
, float
and Vec3b
? 例如,我怎么能告诉空白应该用
ushort
, float
和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
使用
uchar == unsigned char
和ushort == unsigned short
for missing types you could create your own typedef if you want to: 对于缺少类型,您可以创建自己的typedef,如果您想:
typedef Vec<ushort, 2> Vec2us;
or you just access it with am type of same size ( Vec2s
) and convert it afterwards 或者您只是使用相同大小的类型(
Vec2s
)访问它并在之后转换它
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... 但最后我认为理解格式的含义(32位浮点数,3个通道=每个矩阵元素3个浮点值),如果比查看表格要好得多......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.