User avatar
BillyBag2
Posts: 32
Joined: Fri Jun 15, 2012 7:11 am
Contact: Website

Is accelerated image proccessing posible?

Thu Aug 30, 2012 10:23 am

Can the RPi use the GPU to do accelerated image proccessing without displaying the results on screen?
Pi N Chips - pinchips.blogspot.co.uk

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26442
Joined: Sat Jul 30, 2011 7:41 pm

Re: Is accelerated image proccessing posible?

Thu Aug 30, 2012 11:06 am

What specifically do you want to do?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

User avatar
BillyBag2
Posts: 32
Joined: Fri Jun 15, 2012 7:11 am
Contact: Website

Re: Is accelerated image proccessing posible?

Thu Aug 30, 2012 12:39 pm

Things like gamma correction, saturation, HDR, merging two images, colour replacment. If there were multiple input images they would be the same size in pixels and be aligned over eachother. Simple things would be on a per pixel basis. It would be nice to do stuff that was influenced by neighbouring pixels, but being able to do the simple sums on a per-pixel basis would be useful too.

A case study could be merging N aligned images into one to reduce noise, just a simple vector mean.
Pi N Chips - pinchips.blogspot.co.uk

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26442
Joined: Sat Jul 30, 2011 7:41 pm

Re: Is accelerated image proccessing posible?

Thu Aug 30, 2012 12:46 pm

The GPU can already do most of those things (in real time at 30fps) using the onboard ISP, but its difficult to get access to it from the Arm core. I suppose it might be possible with some alterations to the OpenMAX interface to allow input to the ISP from a OMX component rather that the onboard camera.

You can use dispmanx to merge images.

Most are not possible from the Arm right now though.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Janq
Posts: 36
Joined: Sat Jun 02, 2012 3:36 pm

Re: Is accelerated image proccessing posible?

Thu Aug 30, 2012 3:06 pm

BillyBag2 wrote:Things like gamma correction, saturation, HDR, merging two images, colour replacment. If there were multiple input images they would be the same size in pixels and be aligned over eachother. Simple things would be on a per pixel basis. It would be nice to do stuff that was influenced by neighbouring pixels, but being able to do the simple sums on a per-pixel basis would be useful too.

A case study could be merging N aligned images into one to reduce noise, just a simple vector mean.

You can do all of these things with OpenGLES2.0 shaders.

Gamma correction:

vec4 t=texture2D(Texture,uv);
t=pow(t,g_Gamma);


Saturation:

vec4 t=texture2D(Texture,uv);
float luminance=dot(t.xyz,vec3(0.2125,0.7154,0.0721));
t.xyz+=((t.xyz-luminance)*g_Saturation);


HDR is a very vague term - you can't actually display high dynamic range images without a high dynamic range monitor and the PI doesn't support those. You probably mean tone mapping? Look that up, its more complex than a few lines of code ;)


Merging two images:

vec4 t1=texture2D(Texture1,uv);
vec4 t2=texture2D(Texture2,uv);
vec4 t=(t1*g_Blend)+(t2*(1.0-g_Blend))


Colour replacement is also a very vague term - there are lots of ways you can do that (eg. just simple chroma keying by comparing with a colour in the shader and using it as a mask - right up to full on colour correction using a 3D colour cube).

Anyway - the GPU is perfectly capable of doing these tasks just with standard GLES.

User avatar
BillyBag2
Posts: 32
Joined: Fri Jun 15, 2012 7:11 am
Contact: Website

Re: Is accelerated image proccessing posible?

Thu Aug 30, 2012 4:10 pm

Janq wrote:
Anyway - the GPU is perfectly capable of doing these tasks just with standard GLES.
Cool, can you point me at an example? I'm fine with the maths and vertors and stuff. Writing a shader tooks quite simple based on your examples. Also I can lookup getting data out of a file. I guess the example code needs to populate the "textures" with data, "run" the shader then shovel out the result. Thats the bit I have absolutely no idea how to do. Blending is probably a good exmaple as it is multiple input.
Pi N Chips - pinchips.blogspot.co.uk

User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: Is accelerated image proccessing posible?

Thu Aug 30, 2012 4:17 pm

The hardest part appears to be using EGL to make an off screen pbuffer or pixmap to render to, and to get back the result. It's quite a lot of boilerplate code involved.
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

Twinkletoes
Posts: 210
Joined: Fri May 25, 2012 9:44 pm

Re: Is accelerated image proccessing posible?

Fri Sep 07, 2012 8:02 am

Look at the triangle2 demo code in opt/vc/hello_pi. That uses a shader to generate a mandelbrot texture, which you could then read back from the texture buffer using standard openGL.

User avatar
BillyBag2
Posts: 32
Joined: Fri Jun 15, 2012 7:11 am
Contact: Website

Re: Is accelerated image proccessing posible?

Wed Sep 12, 2012 9:03 am

Twinkletoes wrote:Look at the triangle2 demo code in opt/vc/hello_pi. That uses a shader to generate a mandelbrot texture, which you could then read back from the texture buffer using standard openGL.
I'll try this, it sounds like a good foot in the door for what I want.
Pi N Chips - pinchips.blogspot.co.uk

Return to “OpenGLES”