Depth in some opencv methods

Asked

Viewed 87 times

3

What is the parameter depth that appears in many opencv functions? For example from filter2D(), what I understood by what ta in the documentation would be the number of bits to represent the intensity, is correct?

1 answer

2


Depth

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 give more complexity when creating a segmentation by Thresholding, because the variation of colors/intensities is also greater.

So the choice of depth depends on the desired application.

Data Types

To official documentation explains the reason for using these types of Data Types.

In version 4.0.0-beta:

  • 8-bit unsigned integer (uchar)
  • 8-bit Signed integer (schar)
  • 16-bit unsigned integer (ushort)
  • 16-bit Signed integer (short)
  • 16-bit floating-point number (float)
  • 32-bit Signed integer (int)
  • 32-bit floating-point number (float)
  • 64-bit floating-point number (double)

In the Github it is possible to find the Data Types of depth in the code below:

/** @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 version of Opencv are 7 Data Types, plus the legacy Data Type CV_USRTYPE1

Or are 8 Data Types from version 4.x, with the addition of the new CV_16F

Python

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

Returning: ['CV_16S', 'CV_16U', 'CV_32F', 'CV_32S', 'CV_64F', 'CV_8S', 'CV_8U']

Note that depth and type are different. For type is the combination of depth + number of channels.

ddepth

ddepth is the value of depth of the target image, then this must be one of the Data Types of depth or -1, which means the same depth that the source image.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.