Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

In OpenCV , failed to create an RGB image from a Bayer binary file.

$
0
0
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 short[] array such that every cell contains 10 bit pixel. Now I need a way to convert the Bayer short[] array to a JPG image. For that, I am using OpenCV's Mat object and Imgproc.cvtColor. The code is as follows: Mat mat1=new Mat(); mat1.create(1280, 1024, CvType.CV_16U); mat1.put(1280, 1024, charpix); // charpix is short[] Imgcodecs.imwrite("/../codec1.png", mat1); Mat mat2=new Mat(1280,1024,CvType.CV_16U); Imgproc.cvtColor(mat1, mat2, Imgproc.COLOR_BayerBG2RGB); Imgcodecs.imwrite("/../codec2.png", mat2); short[] data1 = new short[mat2.rows() * mat2.cols() * (int)(mat2.elemSize())]; mat2.get(0, 0, data1); BufferedImage bim=new BufferedImage(1024, 1280, BufferedImage.TYPE_USHORT_GRAY); bim.getRaster().setDataElements(0, 0,1024,1280,data1); try { ImageIO.write(bim, "png", new File("/../new.png")); } catch (IOException e) { e.printStackTrace(); } I get no errors but as an output I am only getting a BLACK image for all the 3 images which I am trying to create. 1/4 of each the 3 images shows some color(either gray/rgb depending on cvType/BufferedImageType I use) and the rest part of the images is BLACK.Imgproc is not doing the desired conversion.Am I using Imgcodecs the right way? Does anyone know where I may be wrong ? Any help would be greatly appreciated.

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>