Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV can convert types to depth values via cv::DataType<T>::type

template <typename T>
void myTemplateFunc()
{
    // At RUN time, allocate image of correct type using the VALUE Depth
    cv::Mat img(cv::Size(10,10), cv::DataType<T>::type);

    // ...

    // Access pixel with correct and generic depth - specified at COMPILE time 
    img.at<T>(cv::Point(5,5)) = img.at<T>(cv::Point(1,1));
   // ...
}

myTemplateFunc<uchar>();     // CV_8U
myTemplateFunc<cv::Vec3b>(); // CV_8UC3
myTemplateFunc<cv::Size>();  // CV_32SC2