Convert Mat to 16 bit int
Hi,
I want to convert my 16 bit images from format cv::Mat to 16 bit. Currently, I am using this function
int size = image.total() * image.elemSize(); // number of elements * size of elements
float * bytes = new float[size];
std::memcpy(bytes, &image.data, size * sizeof(float));
return bytes;
which only allows me to use 8 bit images (format bytes). Do you know a function call to convert cv::Mat to my desired bit format?
Best
ManuKlause
aww dear, code above is all wrong (why float? size is also already in bytes)
can't you just use
mat1.convertTo(mat2, CV_16U)
I want to use the data of cv::Mat in CUDA, and CUDA does not support cv::Mat. So, using mat1.convertTo(mat2, CV_16U) wouldnt be helpful.
wait, i probably misread it. are those Mat's 16bit already ?
you could still get
ushort*ps = mat.ptr<ushort>()
Yes, they are 16 bit.
ah, ok, does not need any conversion , then (my bad)