Olivier Grech Olivier Grech - 1 month ago 10
C++ Question

Pointer on a float matrix is considered as *uchar

I'm trying to iterare trough a

cv::Mat
with a pointer.
So I did the following in my function:

template<typename Tin=uchar,typename Tout=float>
inline cv::Mat_<Tout> dct(const cv::Mat_<Tin>& oBlock) {

cv::Mat_<Tout> oOutput(oBlock.size());
Tout *pointeurOut= oOutput.data;

//...
}


However, I'm getting an error at the last line (
Tout *pointeurOut= oOutput.data;
).


'initializing': cannot convert from 'uchar *' to 'float *'


Where does that come from?

Answer

data is always a uchar*.

You should use

oOutput.ptr<Tout>(); 

to get the Tout pointer to the i-th row (by default is the 0-th row, i.e. the beginning of the image)

Comments