Ask Your Question

ocv_user's profile - activity

2016-01-15 07:50:34 -0600 commented answer How can I store a char[] in Matrix Object in OpenCV Java?

Hi, yes thank you. I stored short[] into Mat successfully. Actually, in Java, short data type is signed. In fact java has only signed data type. But what I have stored in my short[] array, is 10-bit unsigned data. Hence, I wanted to use char[] which is the only unsigned type.

2016-01-15 04:48:28 -0600 commented answer How can I store a char[] in Matrix Object in OpenCV Java?

Hi, thank you. What you have mentioned is in C++. I see no such constructor is Java.

2016-01-15 04:42:47 -0600 received badge  Enthusiast
2016-01-14 16:15:40 -0600 asked a question How can I store a char[] in Matrix Object in OpenCV Java?

Hi, I have unsigned data stored in a char[]. The code is:

    Mat mat1=new Mat();
    mat1.create(640, 512, CvType.CV_16UC1);
    mat1.put(0, 0,chararr);

However, put() function does not support this conversion. Is there any other way I can do it? An answer would be appreciated. Thank you.

2016-01-14 04:25:13 -0600 asked a question Imgproc.cvtColor or Imgproc.demosaicing for Bayer to RGB conversion in OpenCV Java

Hi, I would like to know :

1)What is the difference between Imgproc.cvtColor(mat1, mat2, Imgproc.COLOR_BayerBG2RGB) and Imgproc.demosaicing(mat1, mat2,Imgproc.COLOR_BayerBG2RGB) when doing conversion from Bayer to RGB ?

2) In the above case, Imgcodecs.imwrite or BufferedImage's getRaster() is suitable for creating the image ? BufferedImage's getRaster() seems to be slower.

3) Bayer image is unsigned. As Java only supports signed data type , so is storing 10-bit Bayer image in short[] the only solution ?

Answers would be appreciated. Thank you.

2016-01-14 04:12:24 -0600 commented question Unable to store stort[] array in Matrix object : OpenCV Java

Thank you so much. It solved the problem!

2016-01-14 03:48:49 -0600 asked a question Unable to store stort[] array in Matrix object : OpenCV Java

Hi, I am trying to store a short[1280*1024] 1D array in Mat object and and trying to create an image out of it. Below is code:

Mat mat1=new Mat();
mat1.create(1280, 1024, CvType.CV_16UC1);
mat1.put(1280, 1024,pix);  //pix is short[1280*1024]
Imgcodecs.imwrite("/../pic.png", mat1);

The put() function is not able to store all the [1280*1024] elements in the cells of the matrix. Only around 1/4th of the data seems to be stored. The rest are all 0s. I would be grateful if anyone can throw some light on this and tell if this is the right way to store the array into Matrix object.

2016-01-12 11:44:57 -0600 asked a question In OpenCV , failed to create an RGB image from a Bayer binary file.

I have a binary file containing Bayer image in 2-channel BGGR format to 3-channel RGB 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. I see that mat1 is unable to store my short[] in it. Only some mat1 cells have data and rest have all 0s. What is the correct way to store short[] in the array.Any help would be greatly appreciated.

2016-01-12 11:42:07 -0600 answered a question Java : Convert a binary file (received from Bayer sensor) to a Bayer image and then to an RGB image.

It is Imgproc.cvtColor in Java

2016-01-12 11:41:44 -0600 received badge  Supporter (source)
2016-01-12 11:41:38 -0600 received badge  Scholar (source)
2016-01-12 11:41:35 -0600 commented answer Java : Convert a binary file (received from Bayer sensor) to a Bayer image and then to an RGB image.

Thank you so much. Yes, I found it. It is Imgproc.cvtColor in Java

2016-01-10 07:22:02 -0600 received badge  Editor (source)
2016-01-10 07:08:52 -0600 asked a question Java : Convert a binary file (received from Bayer sensor) to a Bayer image and then to an RGB image.

I am receiving a binary file from a Bayer sensor. Every 10 bits in the file represent a pixel. How can I convert the binary file into the raw Bayer image using OpenCV in Java. Later I would also need to convert the Bayer image into the desired grayscale/RGB image. Or can I directly convert the binary file into the grayscale/RGB image ? Any help is appreciated. Thank you so much.