Private members in TypeDepth class [closed]
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
what are you trying to achieve ?
(a use-case might be helpful)
Added the use case.
honestly, imho, you only tried re-inventing NORM_MINMAX in a slower, overcomplicated way.
Based on your tips I managed to reduce my implementation to something a lot more pleasant. Thanks!
Now back to the original topic, those TypeDepth traits are useless for the time being.
but i think, you're right on the TypeDepth. -- as it is, it's utterly useless,and never actually used anywhere, and might be something redundant.
are you bold enough, to raise an official issue here (as in: imho, the whole thing should be removed, not improved)? ;)
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.