Log in or register to post comments

facing problem while using getPixels()

August 5, 2015 - 10:43pm #1

Hi,

I am planning to use separate threads for vuforia camera tracking and rendering .
Instead of using Renderer,drawVideoBackground(), in android, to draw camera preview , i want to use getImage(0).getPixels() which returns a bytebuffer.
I want to use this bytebuffer from vuforia thread and pass it to rendering thread  and  create a texture and use it.

But , getPixels() is returning a bytebuffer which has no.of bytes = width x height. And pixel format is RGB565.
So I assume the byte buffer returned should have no.of bytes = 2 x width x height.
This is the code i am using:

 

Image camImage = mState.getFrame().getImage(0);
    	int width = camImage.getWidth();
    	int height = camImage.getHeight();
    	
    	mCameraBuffer = camImage.getPixels();
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    	
    	mCameraBuffer.rewind();
    	bmp.copyPixelsFromBuffer(mCameraBuffer);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mCamtex[0]);
    	GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
           GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);

I am getting a run time error "buffer not enough for pixels", because of mismatch between bitmap memory and byte buffer returned by getPixels().

 

 

facing problem while using getPixels()

August 11, 2015 - 12:57pm #2

Hi,

Using getPixels per each frame is very time consuming and most likely your frame rate will drop since you would be doing  format conversion, extra copies and texture bindings. I would recommend you to look into the Background Texture Access sample that we provide, that sample shows how to use the video texture instead of reading all the pixels by yourself and creating a texture from that data.

Log in or register to post comments