I have a binary file containing Bayer image in BGGR format. Every pixel is 10 bits. For that I am reading the binary file into byte[] array and then did some bit level manipulation with the byte[] to create an int[] array such that every cell contains 10 bit pixel. Now I need a way to convert the Bayer int[] array to a JPG image. For that, I am using OpenCV's Mat object and Imgproc.cvtColor. The code is as follows: byte[] jpgByteArray = baos.toByteArray(); int[] pix=getPixel(jpgByteArray);
Mat mat1=new Mat();
mat1.create(1280, 1024, CvType.CV_32S);
mat1.put(1280, 1024, pix);
Mat conv1 = new Mat();
mat1.convertTo(conv1, CvType.CV_16U); // Imgproc works only on depth == CV_8U || depth == CV_16U //|| depth == CV_32F.Hence this conversion.
Mat mat2=new Mat(1280,1024,CvType.CV_16U);
Imgproc.cvtColor(conv1, mat2, Imgproc.COLOR_BayerBG2BGR);
int[] data1 = new int[mat2.rows() * mat2.cols() * (int)(mat2.elemSize())];
Mat conv2 = new Mat();
mat2.convertTo(conv2, CvType.CV_32S);
conv2.get(0, 0, data1);
BufferedImage bim=new BufferedImage(1024, 1280, BufferedImage.TYPE_INT_BGR);
bim.getRaster().setDataElements(0, 0,1024,1280,data1);
try {
ImageIO.write(bim, "jpg", new File("..output.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
I get no errors but as an output I am only getting a pure BLACK image. Does anyone know where I am wrong ?