Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why is cv::Mat::data always pointing to a uchar?

I try to read a NEF file using LibRaw and then put it in a cv::Mat. The NEF file stores data as 12bit, this means I need 16 bit, so I ought to use CV_16UC4 like this:

Mat img1(height, width, CV_16UC4);

Libraw stores data as ushort*[4], so I thought that this should work:

for (i = 0; i < iwidth*height; i++) {       
    img1.data[4*i+1] = Processor.imgdata.image[i][0];
    img1.data[4*i+2] = Processor.imgdata.image[i][1];
    img1.data[4*i+3] = Processor.imgdata.image[i][2];
    img1.data[4*i+4] = Processor.imgdata.image[i][3];
}

I also get a build error that data may be lost since a ushort to uchar conversion is going to take place, which makes sense, but still, how do I put data bigger than uchar in the data?