Need to keep track of types of opencv Mats
So I'm using the class Mat
from opencv in a program I'm writing. Mat
looks something like this:
class Mat {
public:
Mat(int width, int height, int type);
template <typename T> T getElt(int x, int y);
int depth();
...
}
The type in the constructor specifies whether elements in the Mat
are float
s, int
s, etc as well as the number of channels in the image. depth()
returns the data type used to store image elements.
Unfortunately I have to call getElt()
in my code. Whenever I do that I use a switch
statement to check the depth of the Mat
so I can call getElt()
with the appropriate template parameter. Doing it that way is pretty verbose, so I was wondering if there was a better way to do it. Could I create a container for a Mat
开发者_高级运维and use template magic create a method that returns a type as opposed to a value? Or could I use macros to make things more efficient and logical?
I'd rather not have to subclass Mat
since there are several methods besides getElt()
for which I have this same issue.
Edit: made the description more accurate.
You're probably looking for Mat_<T>
instead. An black&white image really isn't the same as a greyscale image, and neither is equal to a color image. Those should be separate at compile time.
IIRC the 'type' in openCV MAT corresponds to the image type (ie number of channels) not the data type float/int/char etc.
If you want a templated image class that can transparently work with char/int/bool/double etc - take a look at CImg
精彩评论