Topic locked

Error in reading pixel array

September 1, 2014 - 11:12pm #1

Hi,

Code provided in FAQ "How to access camera image?" throws exception in the line "byte[] pixelArray = pixels.array();" and the exception is 

java.lang.UnsupportedOperationException:
at java.nio.DirectByteBuffer.protectedArray(DirectByteBuffer.java:92)
at java.nio.ByteBuffer.array(ByteBuffer.java:129)
 
Please its urgent I need help.
 
Thanks.
 

Error in reading pixel array

September 4, 2014 - 5:28am #5

You should not use the BitmapFactory.decodebytearray() method, as the camera image is not a PNG or JPEG image.

The correct solution is posted here:

https://developer.vuforia.com/forum/android/camera-image-returns-black

Please follow up in that thread.

(I'll close this one).

 

 

Error in reading pixel array

September 4, 2014 - 4:46am #4

When I convert that byte[] to a bitmap using BitmapFactory.decodebytearray it throws exception.

--- SkImageDecoder::Factory returned null.

 : java.lang.NullPointerException.

Error in reading pixel array

September 3, 2014 - 9:36am #3

See updated code snippet in the FAQ:

https://developer.vuforia.com/forum/faq/android-how-can-i-access-camera-image

in particular, use these lines instead:

byte[] pixelArray = new byte[pixels.remaining()];
pixels.get(pixelArray, 0, pixelArray.length());

 

Error in reading pixel array

September 2, 2014 - 11:46am #2

same error for me. I am using this code:

 

  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
        
        State state = mRenderer.begin();

        Image imageRGB565 = null;
        Frame frame = state.getFrame();
              
        for (int i = 0; i < frame.getNumImages(); ++i) {
            Image image = frame.getImage(i);
            if (image.getFormat() == PIXEL_FORMAT.RGB565) {
                imageRGB565 = image;
                break;
            }
            Log.e(LOGTAG, "Entra 1");
        }
              
        if (imageRGB565 != null) {
        	  int imageWidth = imageRGB565.getWidth();
              int imageHeight = imageRGB565.getHeight();
              int stride = imageRGB565.getStride();
              Log.d("Image", "Image width: " + imageWidth);
              Log.d("Image", "Image height: " + imageHeight);
              Log.d("Image", "Image stride: " + stride);
               
               
              ByteBuffer pixels = imageRGB565.getPixels();
              byte[] pixelArray = pixels.array();
              Log.d("Image", "First pixel byte: " + pixelArray[0]);
            Log.e(LOGTAG, "Entra 2");
        }

 

and the error log:

 

09-02 20:36:17.718: E/AndroidRuntime(9134): Process: com.qualcomm.vuforia.samples.VuforiaSamples, PID: 9134
09-02 20:36:17.718: E/AndroidRuntime(9134): java.lang.UnsupportedOperationException
09-02 20:36:17.718: E/AndroidRuntime(9134): at java.nio.DirectByteBuffer.protectedArray(DirectByteBuffer.java:92)
09-02 20:36:17.718: E/AndroidRuntime(9134): at java.nio.ByteBuffer.array(ByteBuffer.java:129)
09-02 20:36:17.718: E/AndroidRuntime(9134): at com.qualcomm.vuforia.samples.VuforiaSamples.app.ImageTargets.ImageTargetRenderer.renderFrame(ImageTargetRenderer.java:210)
Topic locked