Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between OpenCV type CV_32F and CV_32FC1

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.

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

Thank you all in advance for your help!

like image 209
mlnthr Avatar asked May 30 '16 16:05

mlnthr


People also ask

What is Type CV_32F?

CV_8U : 1-byte unsigned integer ( unsigned char ). CV_32S : 4-byte signed integer ( int ). CV_32F : 4-byte floating point ( float ).

What is mat type 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.

What is Vec3b OpenCV?

Vec3b is the abbreviation for "vector with 3 byte entries" Here those byte entries are unsigned char values to represent values between 0 .. 255. Each byte typically represents the intensity of a single color channel, so on default, Vec3b is a single RGB (or better BGR) pixel.

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.


1 Answers

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

like image 85
Miki Avatar answered Oct 04 '22 18:10

Miki