All of lore.kernel.org
 help / color / mirror / Atom feed
* V4L image grab
@ 2009-08-14 21:36 Rath
  2009-08-15  9:53 ` Dongsoo, Nathaniel Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Rath @ 2009-08-14 21:36 UTC (permalink / raw)
  To: linux-media

Hi,

with this code from the internet I only get pictures with some undefined 
pixels on the top and black pixels on the bottom.

Where's the problem? I only want a simple example for image captureing.

Here is the code:

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <libv4l1.h>
#include <linux/videodev.h>

#define GES_LAENGE (640*480)

unsigned char  bild[GES_LAENGE];

int main()
{
        int fd;
        long laenge;
        struct video_window video_win;
        FILE *bilddatei;

        if((fd = v4l1_open("/dev/video0", O_RDONLY)) == -1)
        {
                printf("Fehler beim Oeffnen von /dev/video0\r\n");
                return 1;
        }
        if( v4l1_ioctl( fd, VIDIOCGWIN, &video_win) == -1)
        {
                printf("Fehler beim setzen der Einstellungen\r\n");
                return 1;
        }
        laenge = video_win.width * video_win.height;
        if( laenge > GES_LAENGE)
        {
                printf("Bild ist groesser als angegeben\r\n");
                return 1;
        }


        if( v4l1_read( fd, bild, laenge) == -1)
        {
                printf("Auslesen der Kamera nicht möglch\r\n");
                return 1;
        }
        if((bilddatei = fopen( "bild.ppm", "w+b")) == NULL)
        {
                printf("Konnte die datei zum schreiben nicht öffnen\r\n");
                return 1;
        }
        v4l1_close(fd);
        fprintf( bilddatei, "P6\n%d %d\n255\n",video_win.width,
video_win.height);
        fwrite( bild, 1, video_win.width*video_win.height,bilddatei);
        fclose(bilddatei);
        return 0;
}

Regards, Joern 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: V4L image grab
  2009-08-14 21:36 V4L image grab Rath
@ 2009-08-15  9:53 ` Dongsoo, Nathaniel Kim
  2009-08-15 18:23   ` Rath
  0 siblings, 1 reply; 4+ messages in thread
From: Dongsoo, Nathaniel Kim @ 2009-08-15  9:53 UTC (permalink / raw)
  To: Rath; +Cc: linux-media

On Sat, Aug 15, 2009 at 6:36 AM, Rath<mailings@hardware-datenbank.de> wrote:
> Hi,
>
> with this code from the internet I only get pictures with some undefined
> pixels on the top and black pixels on the bottom.
>
> Where's the problem? I only want a simple example for image captureing.
>
> Here is the code:
>
> #include <stdio.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <sys/ioctl.h>
> #include <libv4l1.h>
> #include <linux/videodev.h>
>
> #define GES_LAENGE (640*480)
>
> unsigned char  bild[GES_LAENGE];
>
> int main()
> {
>       int fd;
>       long laenge;
>       struct video_window video_win;
>       FILE *bilddatei;
>
>       if((fd = v4l1_open("/dev/video0", O_RDONLY)) == -1)
>       {
>               printf("Fehler beim Oeffnen von /dev/video0\r\n");
>               return 1;
>       }
>       if( v4l1_ioctl( fd, VIDIOCGWIN, &video_win) == -1)
>       {
>               printf("Fehler beim setzen der Einstellungen\r\n");
>               return 1;
>       }
>       laenge = video_win.width * video_win.height;
>       if( laenge > GES_LAENGE)
>       {
>               printf("Bild ist groesser als angegeben\r\n");
>               return 1;
>       }
>
>
>       if( v4l1_read( fd, bild, laenge) == -1)
>       {
>               printf("Auslesen der Kamera nicht möglch\r\n");
>               return 1;
>       }
>       if((bilddatei = fopen( "bild.ppm", "w+b")) == NULL)
>       {
>               printf("Konnte die datei zum schreiben nicht öffnen\r\n");
>               return 1;
>       }
>       v4l1_close(fd);
>       fprintf( bilddatei, "P6\n%d %d\n255\n",video_win.width,
> video_win.height);
>       fwrite( bild, 1, video_win.width*video_win.height,bilddatei);
>       fclose(bilddatei);
>       return 0;
> }
>


Hi Joern,

That code seems to be using v4l1 APIs. How about using current version
of video4linux?
You can find a simple example code at following document:
http://www.linuxtv.org/downloads/video4linux/API/V4L2_API/spec-single/v4l2.html#CAPTURE-EXAMPLE

And about the weird image you got from the v4l1 example code, could be
a pixelformat missmatch or just some noise fetched but I can't say any
further without knowing your environment :-)
Cheers,

Nate

> Regards, Joern
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>



-- 
=
DongSoo, Nathaniel Kim
Engineer
Mobile S/W Platform Lab.
Digital Media & Communications R&D Centre
Samsung Electronics CO., LTD.
e-mail : dongsoo.kim@gmail.com
          dongsoo45.kim@samsung.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: V4L image grab
  2009-08-15  9:53 ` Dongsoo, Nathaniel Kim
@ 2009-08-15 18:23   ` Rath
  2009-08-16  2:37     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 4+ messages in thread
From: Rath @ 2009-08-15 18:23 UTC (permalink / raw)
  To: Dongsoo, Nathaniel Kim; +Cc: linux-media

With the example from the api specifications I get this output:
root@beagleboard:~# ./capture -d /dev/video0
....................................................................................................
Where can I find the captured images?

----- Original Message ----- 
From: "Dongsoo, Nathaniel Kim" <dongsoo.kim@gmail.com>
To: "Rath" <mailings@hardware-datenbank.de>
Cc: <linux-media@vger.kernel.org>
Sent: Saturday, August 15, 2009 11:53 AM
Subject: Re: V4L image grab


On Sat, Aug 15, 2009 at 6:36 AM, Rath<mailings@hardware-datenbank.de> wrote:
> Hi,
>
> with this code from the internet I only get pictures with some undefined
> pixels on the top and black pixels on the bottom.
>
> Where's the problem? I only want a simple example for image captureing.
>
> Here is the code:
>
> #include <stdio.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <sys/ioctl.h>
> #include <libv4l1.h>
> #include <linux/videodev.h>
>
> #define GES_LAENGE (640*480)
>
> unsigned char bild[GES_LAENGE];
>
> int main()
> {
> int fd;
> long laenge;
> struct video_window video_win;
> FILE *bilddatei;
>
> if((fd = v4l1_open("/dev/video0", O_RDONLY)) == -1)
> {
> printf("Fehler beim Oeffnen von /dev/video0\r\n");
> return 1;
> }
> if( v4l1_ioctl( fd, VIDIOCGWIN, &video_win) == -1)
> {
> printf("Fehler beim setzen der Einstellungen\r\n");
> return 1;
> }
> laenge = video_win.width * video_win.height;
> if( laenge > GES_LAENGE)
> {
> printf("Bild ist groesser als angegeben\r\n");
> return 1;
> }
>
>
> if( v4l1_read( fd, bild, laenge) == -1)
> {
> printf("Auslesen der Kamera nicht möglch\r\n");
> return 1;
> }
> if((bilddatei = fopen( "bild.ppm", "w+b")) == NULL)
> {
> printf("Konnte die datei zum schreiben nicht öffnen\r\n");
> return 1;
> }
> v4l1_close(fd);
> fprintf( bilddatei, "P6\n%d %d\n255\n",video_win.width,
> video_win.height);
> fwrite( bild, 1, video_win.width*video_win.height,bilddatei);
> fclose(bilddatei);
> return 0;
> }
>


Hi Joern,

That code seems to be using v4l1 APIs. How about using current version
of video4linux?
You can find a simple example code at following document:
http://www.linuxtv.org/downloads/video4linux/API/V4L2_API/spec-single/v4l2.html#CAPTURE-EXAMPLE

And about the weird image you got from the v4l1 example code, could be
a pixelformat missmatch or just some noise fetched but I can't say any
further without knowing your environment :-)
Cheers,

Nate

> Regards, Joern
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>



-- 
=
DongSoo, Nathaniel Kim
Engineer
Mobile S/W Platform Lab.
Digital Media & Communications R&D Centre
Samsung Electronics CO., LTD.
e-mail : dongsoo.kim@gmail.com
          dongsoo45.kim@samsung.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: V4L image grab
  2009-08-15 18:23   ` Rath
@ 2009-08-16  2:37     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2009-08-16  2:37 UTC (permalink / raw)
  To: Rath; +Cc: Dongsoo, Nathaniel Kim, linux-media

Em Sat, 15 Aug 2009 20:23:43 +0200
"Rath" <mailings@hardware-datenbank.de> escreveu:

> With the example from the api specifications I get this output:
> root@beagleboard:~# ./capture -d /dev/video0
> ....................................................................................................
> Where can I find the captured images?

It would better to use v4l2grab instead.
> 
> ----- Original Message ----- 
> From: "Dongsoo, Nathaniel Kim" <dongsoo.kim@gmail.com>
> To: "Rath" <mailings@hardware-datenbank.de>
> Cc: <linux-media@vger.kernel.org>
> Sent: Saturday, August 15, 2009 11:53 AM
> Subject: Re: V4L image grab
> 
> 
> On Sat, Aug 15, 2009 at 6:36 AM, Rath<mailings@hardware-datenbank.de> wrote:
> > Hi,
> >
> > with this code from the internet I only get pictures with some undefined
> > pixels on the top and black pixels on the bottom.
> >
> > Where's the problem? I only want a simple example for image captureing.
> >
> > Here is the code:
> >
> > #include <stdio.h>
> > #include <unistd.h>
> > #include <fcntl.h>
> > #include <sys/ioctl.h>
> > #include <libv4l1.h>
> > #include <linux/videodev.h>
> >
> > #define GES_LAENGE (640*480)
> >
> > unsigned char bild[GES_LAENGE];
> >
> > int main()
> > {
> > int fd;
> > long laenge;
> > struct video_window video_win;
> > FILE *bilddatei;
> >
> > if((fd = v4l1_open("/dev/video0", O_RDONLY)) == -1)
> > {
> > printf("Fehler beim Oeffnen von /dev/video0\r\n");
> > return 1;
> > }
> > if( v4l1_ioctl( fd, VIDIOCGWIN, &video_win) == -1)
> > {
> > printf("Fehler beim setzen der Einstellungen\r\n");
> > return 1;
> > }
> > laenge = video_win.width * video_win.height;
> > if( laenge > GES_LAENGE)
> > {
> > printf("Bild ist groesser als angegeben\r\n");
> > return 1;
> > }
> >
> >
> > if( v4l1_read( fd, bild, laenge) == -1)
> > {
> > printf("Auslesen der Kamera nicht möglch\r\n");
> > return 1;
> > }
> > if((bilddatei = fopen( "bild.ppm", "w+b")) == NULL)
> > {
> > printf("Konnte die datei zum schreiben nicht öffnen\r\n");
> > return 1;
> > }
> > v4l1_close(fd);
> > fprintf( bilddatei, "P6\n%d %d\n255\n",video_win.width,
> > video_win.height);
> > fwrite( bild, 1, video_win.width*video_win.height,bilddatei);
> > fclose(bilddatei);
> > return 0;
> > }
> >
> 
> 
> Hi Joern,
> 
> That code seems to be using v4l1 APIs. How about using current version
> of video4linux?
> You can find a simple example code at following document:
> http://www.linuxtv.org/downloads/video4linux/API/V4L2_API/spec-single/v4l2.html#CAPTURE-EXAMPLE
> 
> And about the weird image you got from the v4l1 example code, could be
> a pixelformat missmatch or just some noise fetched but I can't say any
> further without knowing your environment :-)
> Cheers,
> 
> Nate
> 
> > Regards, Joern
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-media" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
> 
> 
> 




Cheers,
Mauro

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-08-16  2:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-14 21:36 V4L image grab Rath
2009-08-15  9:53 ` Dongsoo, Nathaniel Kim
2009-08-15 18:23   ` Rath
2009-08-16  2:37     ` Mauro Carvalho Chehab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.