Linux Cairo, webcam displaying images

Discussion in 'Ruby' started by Mike Durham, Nov 10, 2006.

  1. Mike Durham

    Mike Durham Guest

    G'day
    Can anyone please advise me on how to constantly display the output from
    a webcam using Ruby & Cairo?
    I can operate the webcam, write images to disk etc and I can display a
    Gdk::pixbuf okay. It's just the updating of an image on the screen that
    I'm missing.

    The data returned from V4l is a ruby 'string' but how do I display it?
    At first I thought to display a blank Gdk::pixbuf of correct size
    (640x480) and constantly modify it's buffer but I think this might not
    be possible from within Ruby???

    ====
    From the Ruby-Gnome2 site it says:
    Gdk::pixbuf.new(colorspace, has_alpha, bits_per_sample, width, height)
    Creates a new Gdk::pixbuf and allocates a buffer for it. The buffer
    has an optimal rowstride. Note that the buffer is not cleared; you will
    have to fill it completely yourself. Raises an...
    ====

    note "you will have to fill it completely yourself" how is this achieved
    in Ruby?

    Any help would be most welcome.

    Cheers, Mike
    Mike Durham, Nov 10, 2006
    #1
    1. Advertising

  2. Mike Durham

    Kouhei Sutou Guest

    Hi,

    In <>
    "Linux Cairo, webcam displaying images" on Sat, 11 Nov 2006 09:00:08 +0900,
    Mike Durham <> wrote:

    > Can anyone please advise me on how to constantly display the output from
    > a webcam using Ruby & Cairo?


    Data from webcam (String) -> Gdk::pixbuf ->
    Cairo::ImageSurface.new(data, format, width, height, stride) ->
    Cairo::Context.new(Cairo::XXXSurface.new) ->
    context.set_source(image_surface) -> context.paint

    > The data returned from V4l is a ruby 'string' but how do I display it?
    > At first I thought to display a blank Gdk::pixbuf of correct size
    > (640x480) and constantly modify it's buffer but I think this might not
    > be possible from within Ruby???


    Use Gdk::pixbuf.new(data, colorspace, has_alpha, bit_per_sample,
    width, height, rowstride):

    Creates a new Gdk::pixbuf out of in-memory image
    data. Currently only RGB images with 8 bits per sample
    are supported. Raises an Gdk::pixbufError if there was
    not enough memory.

    * data: Image data in 8-bit/sample packed format(String).
    * colorspace: Color space(GdkColorspace) for image data.
    * has_alpha: true if the data has an opacity channel or false.
    * bits_per_sample: Number of bits per color sample.
    * width: Width of image in pixels.
    * height: Height of image in pixels.
    * rowstride: Distance in bytes between row starts.
    * Returns: A newly-created Gdk::pixbuf.

    Thanks,
    --
    kou
    Kouhei Sutou, Nov 11, 2006
    #2
    1. Advertising

  3. Mike Durham

    Kouhei Sutou Guest

    Hi,

    In <>
    "Re: Linux Cairo, webcam displaying images" on Sat, 11 Nov 2006 12:58:41 +0900,
    Kouhei Sutou <> wrote:

    > > Can anyone please advise me on how to constantly display the output from
    > > a webcam using Ruby & Cairo?

    >
    > Data from webcam (String) -> Gdk::pixbuf ->
    > Cairo::ImageSurface.new(data, format, width, height, stride) ->
    > Cairo::Context.new(Cairo::XXXSurface.new) ->
    > context.set_source(image_surface) -> context.paint


    I mistook. Gdk::pixbuf isn't needed.

    Data from webcam (String) ->
    Cairo::ImageSurface.new(data, format, width, height, stride) ->
    Cairo::Context.new(Cairo::XXXSurface.new) ->
    context.set_source(image_surface) -> context.paint

    Thanks,
    --
    kou
    Kouhei Sutou, Nov 11, 2006
    #3
  4. Mike Durham

    Mike Durham Guest

    Kouhei Sutou wrote:
    > Hi,
    >
    > In <>
    > "Re: Linux Cairo, webcam displaying images" on Sat, 11 Nov 2006 12:58:41 +0900,
    > Kouhei Sutou <> wrote:
    >
    >>> Can anyone please advise me on how to constantly display the output from
    >>> a webcam using Ruby & Cairo?

    >> Data from webcam (String) -> Gdk::pixbuf ->
    >> Cairo::ImageSurface.new(data, format, width, height, stride) ->
    >> Cairo::Context.new(Cairo::XXXSurface.new) ->
    >> context.set_source(image_surface) -> context.paint

    >
    > I mistook. Gdk::pixbuf isn't needed.
    >
    > Data from webcam (String) ->
    > Cairo::ImageSurface.new(data, format, width, height, stride) ->
    > Cairo::Context.new(Cairo::XXXSurface.new) ->
    > context.set_source(image_surface) -> context.paint
    >
    > Thanks,
    > --
    > kou
    >

    Thanks for the info kou,
    Just a couple of questions to clarify things if you wouldn't mind.

    > Cairo::ImageSurface.new(data, format, width, height, stride) ->


    is 'data' a Ruby string returned from the V4l?

    what is 'format'?

    Thanks for your help kou
    Mike
    Mike Durham, Nov 11, 2006
    #4
  5. Mike Durham

    Kouhei Sutou Guest

    Hi,

    In <>
    "Re: Linux Cairo, webcam displaying images" on Sat, 11 Nov 2006 15:20:04 +0900,
    Mike Durham <> wrote:

    > Just a couple of questions to clarify things if you wouldn't mind.
    >
    > > Cairo::ImageSurface.new(data, format, width, height, stride) ->

    >
    > is 'data' a Ruby string returned from the V4l?


    Yes, it's a String. But I don't know V4l's data format. So,
    I can't promise you that you can use V4l's data directory.

    > what is 'format'?


    One of the cairo_format_t:
    http://www.cairographics.org/manual/cairo-Image-Surfaces.html#id2598794

    In rcairo, those formats are mapped to Cairo::FORMAT_XXX.


    Thanks,
    --
    kou
    Kouhei Sutou, Nov 11, 2006
    #5
  6. Mike Durham

    Mike Durham Guest

    Kouhei Sutou wrote:
    > Hi,
    >
    > In <>
    > "Re: Linux Cairo, webcam displaying images" on Sat, 11 Nov 2006 15:20:04 +0900,
    > Mike Durham <> wrote:
    >
    >> Just a couple of questions to clarify things if you wouldn't mind.
    >>
    >> > Cairo::ImageSurface.new(data, format, width, height, stride) ->

    >>
    >> is 'data' a Ruby string returned from the V4l?

    >
    > Yes, it's a String. But I don't know V4l's data format. So,
    > I can't promise you that you can use V4l's data directory.
    >
    >> what is 'format'?

    >
    > One of the cairo_format_t:
    > http://www.cairographics.org/manual/cairo-Image-Surfaces.html#id2598794
    >
    > In rcairo, those formats are mapped to Cairo::FORMAT_XXX.
    >
    >
    > Thanks,
    > --
    > kou
    >

    Thanks a lot kou, you're a star.
    Cheers, Mike
    Mike Durham, Nov 11, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Objective Cairo

    , Mar 22, 2006, in forum: Python
    Replies:
    1
    Views:
    343
    Paul Boddie
    Mar 22, 2006
  2. Speed

    Capture USB Webcam Images using C

    Speed, Mar 12, 2007, in forum: C Programming
    Replies:
    2
    Views:
    1,147
    santosh
    Mar 12, 2007
  3. Martin P. Hellwig

    Displaying SVG in tkinter using cairo and rsvg

    Martin P. Hellwig, Feb 15, 2011, in forum: Python
    Replies:
    3
    Views:
    1,495
    Arndt Roger Schneider
    Feb 16, 2011
  4. Mike Durham
    Replies:
    4
    Views:
    126
    Mike Durham
    Oct 13, 2006
  5. Gelonida N
    Replies:
    0
    Views:
    120
    Gelonida N
    Feb 20, 2013
Loading...

Share This Page