I am working on creating different dithering techniques using OpenCV in C++. My current code works only if my Mat is a float. For example say if I have something like this:
Mat image;
cv::Vec3f pixel= image.at< float,3>
image in this case is curr开发者_如何学Pythonently a float, more specifically the type for it is CV_32FC3
.
I want to change it to something like this:
cv::Vec3f pixel= image.at< "Datatype",3>
Is there anyway to represent a datatype as a variable that I can modify depending on the data type for Mat?
Not really. You're using templates, which the compiler has to know about at compile time. That means the data type can't be changed out at runtime (unlike MS .NET).
Think of templates as the C++ equivalent of "#define". A templated function gets compiled & duplicated for each data type that is used.
You'll have to specify each individual data type that you use, sooner or later.
In your case Vec3f is actually a "Vec < float, 3 > ". You could put things in a templated function and use the template symbol in place of "float" for both "Vec<>" and the "image.at".
精彩评论