I'm reading images from a 12 bits per pixel grayscale frame grabber. It returns these images in an array of uint16_t, where the 4 msb are 0. I'm packing this array into an array of uint8_t (2 uint16_t give 3 uint8_t) and saving it to disk raw. So the resulting file is a bunch of 12 bit chunks one after the other in big endian.
Later on, I'd like to read such a file and get its histogram using calcHist
. I'm reading the file into an std::vector<uint8_t>
, unpacking it into a std::vector<uint16_t>
(3 uint8_t give 2 uint16_t, with the 4 msb zeroed). So far, everything works.
I'm trying to display the image with OpenCV using the following:
cv::Mat img(1024, 1280, CV_16UC1, &data[0]); // data is my std::vector<uint16_t> cv::imshow("Image", img); cv::waitKey(0);
I'm expecting an image that looks like this, but what I'm getting is this.
Any help would be appreciated!