openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.93k stars 2.55k forks source link

Android camera example doesn't display image on some devices #2923

Open ayberkozgur opened 10 years ago

ayberkozgur commented 10 years ago

I copied the Android camera example (it's basically identical besides the names) and I can't get it to display the camera image on my Note II; on the Note 10.1 it works just fine. Killing and relaunching the app doesn't work. All I can see is empty white space or occasionally a completely white image (whiter than the background so it stands out) where the camera image is supposed to be.

The Note II LTE (GT-N7105) has Cyanogenmod 10.2.0-t0lte on it (based on Android 4.3.1). It has a Mali-400MP4 GPU with GLES 2.0 support.

The Note 10.1 (SM-P600) has the official Samsung rom (based on Android 4.3). It has a Mali-T628 GPU with GLES 3.0 support.

arturoc commented 10 years ago

This is a really hard bug to solve for every device: devices with android 2.x or 3.x didn't need any surface to start the preview, then with 4.0 you need to have a surface attached to the camera or it won't start sending frames. There's 2 kind of surfaces the "normal" surface has to be mapped on to an android view, so if you want to do GL you need to hide that surface somehow, get pixels through a callback and upload them into a texture. There's also a texture surface, this is the one we use, it's ideal for GL because we get the texture and the pixels, it should be slightly faster than uploading the texture in OF since it's done in a different thread and we avoid the problems of having to hide a surface which is really tricky. The problem is that some devices have buggy implementations of the surface texture and won't work with that. I've also noticed that in some phones which original OS didn't supported surface textures, using cianogenmod or any other non official rom, you get surface texture support but it won't work, so this might be the case of the problem you are having.

ayberkozgur commented 10 years ago

In another application (unrelated to oF), I'm getting the camera preview through a callback (there's no surface involved), loading that into a texture and rendering the texture onto a mesh. There's also 3D rendering, color space conversion in shader and OpenCV image processing involved, so this is probably the cleanest way; although it is probably slower than attaching a SurfaceTexture. This method fully works with both of the above devices, although I had reports of an LG device and a Google Nexus failing to get preview callbacks. I'll report back here if I can find more robust methods.

arturoc commented 10 years ago

i think this method works for most devices since it's detecting if surfacetexture is supported by the api and using it only in that case. i think it only doens't work when the device doesn't have official support for surfacetexture but the loaded rom does.

we could add a method to optionally disable the surface texture and instead upload the pixels manually to a texture

ayberkozgur commented 10 years ago

I've just implemented an application where I get the camera image onto a SurfaceTexture and draw it on a mesh on the screen (in pure GLES, completely unrelated to oF). It works on both devices, so it seems to me that the problem is unrelated to SurfaceTextures.

whatisor commented 8 years ago

It also failed on Nexus 5x (6.0), HTC Desire 610 (4.4). :(. Only grabberImage shows image;