Return Mat_<float> data not uchar
I'm refactoring some code from cimg to opencv. I have the following lines that should return Mat_<float>.data
.
// Get a pointer to the data.
// T* Data() { return image_.data(); } <-cimg calls
// const T* Data() const { return image_.data(); } <-cimg.calls
T* Data() { return image_.data; }
const T* Data() const { return image_.data; }
but I get a compile error:
error: cannot initialize return object of type 'float *' with an lvalue of type 'uchar *' (aka 'unsigned char *')
T* Data() { return image_.data; }
Other part of the code:
cv::Mat_<T> image_;
...
image_ = cv::imread(filename.c_str(), CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
From what I've read Mat.data is of type uchar. But shouldn't data be float when I use Mat_<float>
?
Thanks, Jason
CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH
-- that's one of the few situations with opencv, where you cannot estimate the type at compile time.thus you cannot use "typed" template Mat's here.
reconsider your design.
Ok, then I should use
cv::imread(filename.c_str(), CV_LOAD_IMAGE_COLOR)
But are you also saying thatcv::Mat_<T> image_
will not be loaded as a float whenimread
is called?cv::imread(filename.c_str(), CV_LOAD_IMAGE_COLOR)
would return CV_8UC3 data, uchar, not float.again why do you insist on using
Mat_<float>
(or any templated version ?)This is an older code base and the main class/object is built on templates.
maybe that's a bad idea. cv::Mat is NOT a template class by default
Well that's unfortunate. Isn't that what
cv::Mat_<T>
is for? To handle template classes."Isn't that what
cv::Mat_<T>
is for?" sure.again, in 90% of all cases you know the type offhand.
but you can't use templates, if the type changes / is determined at runtime