Ask Your Question

Revision history [back]

Private members in TypeDepth class

This is more a question for the developer/contributor team.

I was looking for methods to infer the native type automatically based on the depth value and came across the TypeDepth class on core/traits.hppgithub.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/traits.hpp#L274 (cannot post links yet). Unfortunately all its members are private and the thing is not really usable nor used anywhere.

Any particular reasons for this? e.g.: it's implementation/architecture dependent and therefore cannot be used reliably, something of that sort.

If there's no actual reason, could you expose the members in the next releases?

Cheers

Private members in TypeDepth class

This is more a question for the developer/contributor team.

I was looking for methods to infer the native type automatically based on the depth value and came across the TypeDepth class on core/traits.hppgithub.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/traits.hpp#L274 (cannot post links yet). Unfortunately all its members are private and the thing is not really usable nor used anywhere.

Any particular reasons for this? e.g.: it's implementation/architecture dependent and therefore cannot be used reliably, something of that sort.

If there's no actual reason, could you expose the members in the next releases?

Edit: Intended use case

I wanted to generate a colormap representation for a matrix of type CV_32FC1, but currently the applyColormap only works with matrices of type CV_8UC1 or CV_8UC3. In order to overcome this limitation, I wrote a function which which receives a generic cv::Mat, infers the underlying depth and channels, generates an intermediate matrix which will be a normalized version of the input matrix i.e., the maximum value found on input will correspond to 255 and the minimum value to 0, with everything else in between will be mapped linearly. I wanted to this generically, so that it works with other types like CV_16S, CV_16U, CV_32F, CV_64F, etc...

Below is an initial version of what was going to be my implementation.

template<int OpenCvDepthT> void
colormap ( const cv::Mat &input,
           const cv::ColormapTypes colormap,
           cv::Mat &out)
{
  typedef typename cv::TypeDepth<OpenCvDepthT>::value_type T;

  auto const minmax = std::minmax_element((const T*)input.data , (const T*) input.dataend);
  const T range = *minmax.second - *minmax.first;

  // create normalized matrix
  cv::Mat tmp (input.size (), CV_MAKETYPE (CV_8U, input.channels ()));

  const T* ptr1 = (T *) input.data;
  uint8_t* ptr2 = (uint8_t *) tmp.data;
  for (; ptr1 != (const T *) input.dataend && ptr2 != (uint8_t *)tmp.dataend; ++ptr1, ++ptr2)
    *ptr2 = (uint8_t) ((T) 255 * (*ptr1 - *minmax.first) / range);

  cv::applyColorMap (tmp, out, colormap);
}

Cheers

Private members in TypeDepth class

This is more a question for the developer/contributor team.

I was looking for methods to infer the native type automatically based on the depth value and came across the TypeDepth class on core/traits.hppgithub.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/traits.hpp#L274 (cannot post links yet). . Unfortunately all its members are private and the thing is not really usable nor used anywhere.

Any particular reasons for this? e.g.: it's implementation/architecture dependent and therefore cannot be used reliably, something of that sort.

If there's no actual reason, could you expose the members in the next releases?

Edit: Intended use case

I wanted to generate a colormap representation for a matrix of type CV_32FC1, but currently the applyColormap only works with matrices of type CV_8UC1 or CV_8UC3. In order to overcome this limitation, I wrote a function which which receives a generic cv::Mat, infers the underlying depth and channels, generates an intermediate matrix which will be a normalized version of the input matrix i.e., the maximum value found on input will correspond to 255 and the minimum value to 0, with everything else in between will be mapped linearly. I wanted to this generically, so that it works with other types like CV_16S, CV_16U, CV_32F, CV_64F, etc...

Below is an initial version of what was going to be my implementation.

template<int OpenCvDepthT> void
colormap ( const cv::Mat &input,
           const cv::ColormapTypes colormap,
           cv::Mat &out)
{
  typedef typename cv::TypeDepth<OpenCvDepthT>::value_type T;

  auto const minmax = std::minmax_element((const T*)input.data , (const T*) input.dataend);
  const T range = *minmax.second - *minmax.first;

  // create normalized matrix
  cv::Mat tmp (input.size (), CV_MAKETYPE (CV_8U, input.channels ()));

  const T* ptr1 = (T *) input.data;
  uint8_t* ptr2 = (uint8_t *) tmp.data;
  for (; ptr1 != (const T *) input.dataend && ptr2 != (uint8_t *)tmp.dataend; ++ptr1, ++ptr2)
    *ptr2 = (uint8_t) ((T) 255 * (*ptr1 - *minmax.first) / range);

  cv::applyColorMap (tmp, out, colormap);
}

Cheers