Ask Your Question

ewanko08's profile - activity

2014-11-22 23:45:15 -0600 asked a question Getting a blank image

I have a jpg file that is saved in the computer that I am trying to load, perform some image processing algorithm in it, then output the file. The jpg file is an image taken from Google Glass. My final application will be receiving images from glass (byte array data type) and it will perform image processing algorithms in it.

For now, I'm trying to create a helper class that will accept byte array (input image) and return another byte array as the output. I have this running in a Java application and the input and output image will be displayed in the UI. I have the below method:

public byte[] ProcessImage(byte[] input) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    Mat rgba = new Mat(240, 320, CvType.CV_8U);
    rgba.put(0, 0, input);

    Imgproc.cvtColor(rgba, rgba, Imgproc.COLOR_RGB2GRAY, 0);

    //Convert back to byte[] and return
    byte[] return_buff = new byte[(int) (rgba.total() * rgba.channels())];
    rgba.get(0, 0, return_buff);
    return return_buff;
}

When the output byte array is displayed in the UI, it is just blank. But when I comment out the Imgproc.cvtColor line, I get an output image (which is the same as the input image).

Does anyone have any clue why the Imgproc call doesn't work. Is this related to some kind of image encoding? I would appreciate any help.