Can you capture screen and run a filter on Android? [closed]

asked 2017-01-13 21:07:20 -0600

adanecito gravatar image

updated 2017-01-14 00:56:01 -0600

Hi, I have written my Android app (java) so it can capture my Android app screen (framebuffer) put it in a bitmap then run a filter on the bitmap then put it back into a resultant bitmap to display as a texture overlay. I am using glreadpixels for opengl es 3.0 to get the image. It is slower than I like it to be and was looking at using the NDK but was wondering if OpenCV can do that. If so what example(s) should I look at to accomplish that goal?

So basically the steps are that I am doing now:

  1. Capture the frame of pixels using GLES30.glreadpixels()
  2. Convert the captured frame buffer pixels from GLES30.GL_RGBA to RGBA_8888 and put into Bitmap
  3. Run the Bitmap from step 2 through the desired filter producing a resultant Bitmap
  4. Convert the Bitmap to a texture
  5. Overlay texture on glsurfaceview.

I want to do steps 1-4 faster using OpenCV. Step 1 is taking me around 60ms, step 2 around 200ms I have not measured the other steps yet. The steps are all done right now using java and GLES30 outside of NDK. If I can do all easily and quick using NDK with OpenCV that is good but most of the examples I have seen use a camera and save to a file. So not sure I can use OpenCV to do what I need.

Thanks for the help! -Tony

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2017-01-14 03:47:07.374160

Comments

no idea, what kind of"filter" you want to apply, but - most likely, you don't want to abuse opencv (which is a computer-vision library, not photoshop or instagram) for this.

it would seem far more effective, to implement your filter as a fragment shader directly on the GPU, so none of your steps 1--5 would be nessecary.

berak gravatar imageberak ( 2017-01-14 03:21:40 -0600 )edit

Hi Berak, Thanks for the feedback but OpenCV has image manipulation example for the Android and I was thinking of Sharpness, Contrast simple filters. Also, OpenCV was recommended on StackOverflow to use by someone else. I was concerned it might be too big and slow for what I wanted and you confirmed my concerns. -Tony

adanecito gravatar imageadanecito ( 2017-01-14 12:05:22 -0600 )edit

still, believe me on the fragment shaders !

berak gravatar imageberak ( 2017-01-14 12:32:03 -0600 )edit

I am using Renderscript already for the filters so do not need shaders. I will look into them to do the other things I do so thanks for the advice.

adanecito gravatar imageadanecito ( 2017-01-14 12:36:20 -0600 )edit

I am also looking at using the NDK right now. What I was hoping is to use OpenCV to do all these things already in a highly efficient manner rather than me learning how to design/implement/test it over a longer period of time. Since I need real-time processing of each frame you seem to indicate that is what OpenCV is not designed to do. No problem, I will look for a different library that is optimized for real-time processing.

adanecito gravatar imageadanecito ( 2017-01-14 13:00:51 -0600 )edit

I discovered that shaders do not support glreadpixels and in regards to NDK most companies do not support OpenGL ES 3.0 at the hardware level so libglesv3.so needed to link to at runtime can not be found on the device.

adanecito gravatar imageadanecito ( 2017-01-15 10:12:02 -0600 )edit