Difference between OpenCV type CV_32F and CV_32FC1

后端 未结 1 1975
慢半拍i
慢半拍i 2021-01-04 01:16

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

相关标签:
1条回答
  • 2021-01-04 01:36

    The value for both CV_32F and CV_32FC1 is 5 (see explanation below), so numerically there is no difference.

    However:

    • CV_32F defines the depth of each element of the matrix, while
    • CV_32FC1 defines both the depth of each element and the number of channels.

    A few examples...

    Many functions, e.g. Sobel or convertTo, require the destination depth (and not the number of channels), so you do:

    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_32F is defined as:

     #define CV_32F  5
    

    while CV_32FC1 is defined as:

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

    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;
    }
    

    0 讨论(0)
提交回复
热议问题