Ask Your Question

Revision history [back]

How can I get the value type for a cvMat?

I'm trying to get the value type for an element of my matrix and avoid having to hardcode it in order to maximize portability and compatibility with possible future changes.

The obvious way for me would seem to use TypeDev::value_type as defined in traits.cpp (located here: https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/traits.hpp)

Unfortunately the value_type member is defined as private, which I don't quite understand. Is there another way to access this?

To clarify with an example, I'm trying to do something like this:

using Type16S = cv::TypeDepth<CV_16S>::value_type;

In order to use the new type defenition in such a way:

cv::Mat matrix(10,10, CV_16S)
Type16S* pointer = matrix.ptr<Type16S>(1);
click to hide/show revision 2
None

updated 2018-06-04 10:30:41 -0500

berak gravatar image

How can I get the value type for a cvMat?

I'm trying to get the value type for an element of my matrix and avoid having to hardcode it in order to maximize portability and compatibility with possible future changes.

The obvious way for me would seem to use TypeDev::value_type as defined in traits.cpp (located here: https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/traits.hpp)

Unfortunately the value_type member is defined as private, which I don't quite understand. Is there another way to access this?

To clarify with an example, I'm trying to do something like this:

using Type16S = cv::TypeDepth<CV_16S>::value_type;

In order to use the new type defenition in such a way:

cv::Mat matrix(10,10, CV_16S)
Type16S* pointer = matrix.ptr<Type16S>(1);
click to hide/show revision 3
None

updated 2018-06-04 10:36:22 -0500

berak gravatar image

How can I get the value type for a cvMat?cv::Mat?

I'm trying to get the value type for an element of my matrix and avoid having to hardcode it in order to maximize portability and compatibility with possible future changes.

The obvious way for me would seem to use TypeDev::value_type TypeDepth::value_type as defined in traits.cpp (located here: https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/traits.hpp)

Unfortunately the value_type member is defined as private, which I don't quite understand. Is there another way to access this?

To clarify with an example, I'm trying to do something like this:

using Type16S = cv::TypeDepth<CV_16S>::value_type;

In order to use the new type defenition in such a way:

cv::Mat matrix(10,10, CV_16S)
Type16S* pointer = matrix.ptr<Type16S>(1);