C++ OpenCV 类型 CV_32F 和 CV_32FC1 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37530368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between OpenCV type CV_32F and CV_32FC1
提问by mlnthr
I would like to know if there is any difference between OpenCV types CV_32F and CV_32FC1? I already know that 32F stands for a "32bits floating point" and C1 for "single channel", but further explanations would be appreciated.
我想知道 OpenCV 类型 CV_32F 和 CV_32FC1 之间是否有任何区别?我已经知道 32F 代表“32 位浮点”,C1 代表“单通道”,但进一步的解释将不胜感激。
If yes, how are they different / which one should I use in which specific cases? As you might know that openCV types can get very tricky...
如果是,它们有什么不同/我应该在哪些特定情况下使用哪个?您可能知道 openCV 类型会变得非常棘手......
Thank you all in advance for your help!
在此先感谢大家的帮助!
回答by Miki
The value for both CV_32F
and CV_32FC1
is 5
(see explanation below), so numerically there is no difference.
两者的值CV_32F
和CV_32FC1
被5
(见下面的说明),所以数值没有差别。
However:
然而:
CV_32F
defines the depth of each element of the matrix, whileCV_32FC1
defines both the depth of each element and the number of channels.
CV_32F
定义矩阵的每个元素的深度,而CV_32FC1
定义每个元素的深度和通道数。
A few examples...
几个例子...
Many functions, e.g. Sobelor convertTo, require the destination depth (and notthe number of channels), so you do:
许多函数,例如Sobel或convertTo,需要目标深度(而不是通道数),因此您可以:
Sobel(src, dst, CV_32F, 1, 0);
src.convertTo(dst, CV_32F);
But, when creating a matrix for example, you must also specify the number of channels, so:
但是,例如在创建矩阵时,您还必须指定通道数,因此:
Mat m(rows, cols, CV_32FC1);
Basically, every time you should also specify the number of channels, use CV_32FCx
. If you just need the depth, use CV_32F
基本上,每次您还应该指定通道数时,请使用CV_32FCx
. 如果您只需要深度,请使用CV_32F
CV_32F
is defined as:
CV_32F
定义为:
#define CV_32F 5
while CV_32FC1
is defined as:
而CV_32FC1
定义为:
#define CV_CN_SHIFT 3
#define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
#define CV_32FC1 CV_MAKETYPE(CV_32F,1)
which evaluates to 5
.
其评估为5
.
You can check this with:
您可以通过以下方式检查:
#include <opencv2\opencv.hpp>
#include <iostream>
int main()
{
std::cout << CV_32F << std::endl;
std::cout << CV_32FC1 << std::endl;
return 0;
}