tomi
tomi

Reputation: 535

faster camera preview using OpenGL?

Writing an app which takes the preview frames from camera does some transformation to it and then displays it on screen.

in

public void onPreviewFrame(byte[] data, Camera camera) {}

I take the data do yuv2rgb and some pixel manipulation in JNI in another thread. Then I create bitmap from the RGB int array and draw it using

canvas.drawBitmap(bmp, 0, 0, null);

I get around 15-20FPS on HTC Nexus One at 640x480 and 30+ FPS on Samsung Galaxy S II

I am wondering if I could speed things up by doing the drawing using Android OpenGL ES? I would be following this guide: http://obviam.net/index.php/texture-mapping-opengl-android-displaying-images-using-opengl-and-squares/

Upvotes: 4

Views: 4513

Answers (2)

tomi
tomi

Reputation: 535

Implemented OpenGL ES and it does help with performance

Upvotes: 2

vikky.rk
vikky.rk

Reputation: 4149

Are you using SurfaceView for your camera App? The preview frame that you get is a copy of the actual frame that gets displayed on the screen. I am guessing you add another view to display the callback preview frames.

I am not a graphics guy but why don't you try SurfaceTexture. You can use setpreviewtexture() instead of setpreviewwindow(). This way Camera Service will send the buffers directly to the app, instead of making a copy and also queuing it to the AndroidNativeWindow. This might improve your performance.

This is how android Camera app Panorama works. You can find the source code here

Upvotes: 4

Related Questions