What is the depth
parameter that appears in many opencv functions? For example of filter2D()
, what I understood by what is in the documentation would be the number of bits to represent the intensity, is it correct?
What is the depth
parameter that appears in many opencv functions? For example of filter2D()
, what I understood by what is in the documentation would be the number of bits to represent the intensity, is it correct?
It is the Data Type of each element of the image, that is, the accuracy of each pixel. The more bits per pixel, the better the representation of color differences and intensities.
On the other hand, this can be more complex when creating a segmentation by Thresholding
, as the color / intensity variation is larger as well.
So the choice of depth
depends on the application you want.
A official documentation explains the reason for using these types of Data Types.
In version 4.0.0-beta:
Github Types of depth
in the following code:
/** @brief A helper class for cv::DataType
The class is specialized for each fundamental numerical data type supported by OpenCV. It provides
DataDepth<T>::value constant.
*/
template<typename _Tp> class DataDepth
{
public:
enum
{
value = DataType<_Tp>::depth,
fmt = DataType<_Tp>::fmt
};
};
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
template<int _depth> class TypeDepth
{
#ifdef OPENCV_TRAITS_ENABLE_LEGACY_DEFAULTS
enum { depth = CV_USRTYPE1 };
typedef void value_type;
#endif
};
template<> class TypeDepth<CV_8U>
{
enum { depth = CV_8U };
typedef uchar value_type;
};
template<> class TypeDepth<CV_8S>
{
enum { depth = CV_8S };
typedef schar value_type;
};
template<> class TypeDepth<CV_16U>
{
enum { depth = CV_16U };
typedef ushort value_type;
};
template<> class TypeDepth<CV_16S>
{
enum { depth = CV_16S };
typedef short value_type;
};
template<> class TypeDepth<CV_32S>
{
enum { depth = CV_32S };
typedef int value_type;
};
template<> class TypeDepth<CV_32F>
{
enum { depth = CV_32F };
typedef float value_type;
};
template<> class TypeDepth<CV_64F>
{
enum { depth = CV_64F };
typedef double value_type;
};
template<> class TypeDepth<CV_16F>
{
enum { depth = CV_16F };
typedef float16_t value_type;
};
#endif
//! @}
Depending on the OpenCV version, there are 7 Data Types plus the legacy Data Type CV_USRTYPE1
Or it's 8 Data Types from version 4.x, with the addition of the new CV_16F
In OpenCV 3.4.3 and Python 3.x some attributes can be obtained with [(i,type(getattr(cv2,i))) for i in dir(cv2)]
And the list of data types of depth
:
import cv2
import re
depths = [i for i in dir(cv2) if re.search('^CV_(?:\d+[A-Z]{1}|USRTYPE1)$', i, re.IGNORECASE)]
print(depths)
That returns: ['CV_16S', 'CV_16U', 'CV_32F', 'CV_32S', 'CV_64F', 'CV_8S', 'CV_8U']
Note that
depth
andtype
are different . Becausetype
is the combination ofdepth
+ number of channels.
ddepth
is the value of depth
of the target image, so this must be some of the Data Types of depth
or -1, which means the same depth
as the source image.