As per cv::Mat Class Reference, one of the constructor is:
Mat (int rows, int cols, int type, void *data, size_t step=AUTO_STEP)
Now, I have rs2::frame and I want to convert them to cv::Mat. So, I have defined one function, and in the conversion, I want to specify the cv::Mat::type i.e. whether the output cv::Mat should be of type CV_8SC1 or CV_16SC1 or so on.
As of now, my function is something like this:
cv::Mat foo(rs2::frame fr, std::string mat_type) {
.
.
.
}
For the mat_type, as shown above, I'm passing the string i.e. "CV_8SC1", "CV_16SC1", etc and in the function body, I'm manually comparing the strings:
.
.
if(mat_type == "CV_8SC1") {
return cv::Mat(width, height, CV_8SC1, ...);
} else if ...
.
.
.
else {
}
However, this is not very efficient, right? Let say, in the future, if I need another type of cv::Mat then I have to update the function by adding a new condition to if... else... statements.
So, how can I avoid this and do something else which is more efficient? I mean, is there any way to pass the cv::Mat::type directly rather than passing an equivalent string(s) and then comparing in the function body?
Just to clarify in advance: my question is different from these questions: