magnatag
Posts: 33
Joined: Tue Mar 04, 2014 8:39 pm

Draw a white line in the center of video?

Tue May 27, 2014 4:31 pm

Hello,

I am trying to create a manual "assist" system of sorts for one of my projects and I envision it as having a live feed from RPi with a line drawn in the middle of the screen to help with lining things up. Is there a way to overlay a 1px center line on a video feed from RPi camera? I can do it with OpenCV but that really kills my framerate. I was hoping maybe there is an overlay function for something like raspivid? The video output does not have to be saved.

Thanks!

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7513
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Draw a white line in the center of video?

Tue May 27, 2014 5:52 pm

Create a MMAL video_render component.
Set the port format to RGB888 or similar
Specify the display rectangle with the appropriate co-ords that you want to fill, and a layer higher than anything else on screen (most things are at 0, raspistill/vid overlay is at 2)
Enable it
Pass it a buffer that you've memset to 0xFF.

Slightly simplified, but you get the idea.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

magnatag
Posts: 33
Joined: Tue Mar 04, 2014 8:39 pm

Re: Draw a white line in the center of video?

Thu May 29, 2014 3:52 pm

Thanks 6by9, but this is a bit above my skill level at the moment.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7513
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Draw a white line in the center of video?

Thu May 29, 2014 4:10 pm

Do you actually want it on the final images from the camera, or only on the display?
On my list of "nice things to do" is a GPU-side video_overlay component to add an overlay to the images as they pass through the pipe. That will be altering to the main images though which may not be what you want.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5369
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Draw a white line in the center of video?

Thu May 29, 2014 4:13 pm

Try running /opt/vc/src/hello_pi/hello_dispman when camera viewfinder is up. It should plot some bitmaps on top of viewfinder.
That may be a good starting point.

Yggdrasil
Posts: 138
Joined: Sun Aug 26, 2012 8:45 pm

Re: Draw a white line in the center of video?

Thu May 29, 2014 4:20 pm

Hello,

I'm unsure if this would be simpler for you, but when you're able to compile Picam_gpu (see http://robotblogging.blogspot.de/2013/1 ... ng-on.html ), you can change the openGL shader (i.e simplefragshader.glsl) and add something like

Code: Select all

varying vec2 tcoord;
uniform sampler2D tex;
void main(void) 
{
 gl_FragColor = texture2D(tex,tcoord);
 if( tcoord.y < 0.52 && tcoord.y > 48 ){
  gl_FragColor = vec4(1.0);
 }
}
If you can't compile the program, you can use the official sourcecode from RaspiVid. Download the userland repository and look into /userland/host_applications/linux/apps/raspicam/gl_scenes/mirror.c
You has to adapt the shader which is described in the property '.fragment_source'.
Moreover, you has to add the command line arguments, to enable the opengl output ;)

Disadvantage of the approach is the extra complexity given by the openGL stuff...

magnatag
Posts: 33
Joined: Tue Mar 04, 2014 8:39 pm

Re: Draw a white line in the center of video?

Thu May 29, 2014 4:53 pm

6by9 wrote:Do you actually want it on the final images from the camera, or only on the display?
On my list of "nice things to do" is a GPU-side video_overlay component to add an overlay to the images as they pass through the pipe. That will be altering to the main images though which may not be what you want.
I am only using the camera stream to zoom in on an object and provide a center line for reference to help the operator of my machine. Since this is all done in real time, I do not need to save the output and therefore it wont matter to me if the final product has the overlay saved. It would definitely be a "nice thing" and I am looking forward to using it whenever it is implemented!

magnatag
Posts: 33
Joined: Tue Mar 04, 2014 8:39 pm

Re: Draw a white line in the center of video?

Thu May 29, 2014 4:53 pm

dom wrote:Try running /opt/vc/src/hello_pi/hello_dispman when camera viewfinder is up. It should plot some bitmaps on top of viewfinder.
That may be a good starting point.
I'll give this a look, thanks!

magnatag
Posts: 33
Joined: Tue Mar 04, 2014 8:39 pm

Re: Draw a white line in the center of video?

Thu May 29, 2014 4:54 pm

Yggdrasil wrote:Hello,

I'm unsure if this would be simpler for you, but when you're able to compile Picam_gpu (see http://robotblogging.blogspot.de/2013/1 ... ng-on.html ), you can change the openGL shader (i.e simplefragshader.glsl) and add something like

Code: Select all

varying vec2 tcoord;
uniform sampler2D tex;
void main(void) 
{
 gl_FragColor = texture2D(tex,tcoord);
 if( tcoord.y < 0.52 && tcoord.y > 48 ){
  gl_FragColor = vec4(1.0);
 }
}
If you can't compile the program, you can use the official sourcecode from RaspiVid. Download the userland repository and look into /userland/host_applications/linux/apps/raspicam/gl_scenes/mirror.c
You has to adapt the shader which is described in the property '.fragment_source'.
Moreover, you has to add the command line arguments, to enable the opengl output ;)

Disadvantage of the approach is the extra complexity given by the openGL stuff...
I'd like to keep this as KISS as possible for the sake of my sanity.

lagurus
Posts: 46
Joined: Wed Aug 07, 2013 8:02 am

Re: Draw a white line in the center of video?

Thu Jul 31, 2014 10:47 am

6by9 wrote: On my list of "nice things to do" is a GPU-side video_overlay component to add an overlay to the images as they pass through the pipe. That will be altering to the main images ...
Any progress in GPU-side overlay?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7513
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Draw a white line in the center of video?

Thu Jul 31, 2014 10:51 am

lagurus wrote:
6by9 wrote: On my list of "nice things to do" is a GPU-side video_overlay component to add an overlay to the images as they pass through the pipe. That will be altering to the main images ...
Any progress in GPU-side overlay?
None as yet, and may not happen following recent events (see sig). I've added it on to my list to remind myself.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Camera board”