Ask Your Question

Sergio Agostinho's profile - activity

2017-02-02 12:55:50 -0600 commented question Private members in TypeDepth class

Sure thing. I was going to originally, but since it's not really an issue I decided to use the Q&A forum first. I wouldn't go as far as removing it, since I do see a use for it.

2017-02-01 19:15:08 -0600 received badge  Student (source)
2017-02-01 17:42:01 -0600 commented question Private members in TypeDepth class

Based on your tips I managed to reduce my implementation to something a lot more pleasant. Thanks!

void
colormap ( const cv::Mat &input,
           const cv::ColormapTypes colormap,
           cv::Mat &out)
{
  cv::Mat tmp, tmp2;
  cv::normalize (input, tmp, 255, 0, cv::NORM_MINMAX);
  tmp.convertTo (tmp2, CV_8U);
  cv::applyColorMap (tmp2, out, colormap);
}

Now back to the original topic, those TypeDepth traits are useless for the time being.

2017-02-01 15:52:53 -0600 commented question Private members in TypeDepth class

Added the use case.

2017-02-01 15:52:01 -0600 received badge  Editor (source)
2017-02-01 13:33:17 -0600 asked a question 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.hpp. 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