Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Sun Jun 22, 2008 10:42 am 
Offline

Joined: Sat Jun 21, 2008 8:13 pm
Posts: 7
Hi , I'd like to run on my board:

http://www.olimex.com/dev/sam9-L9260.html

this code to take a photo by a webcam plugged on the USB port and save it on a Secure Digital on board:

/*
main.c
Simple V4L1 applet - Capture one frame from /dev/video0 and save
it as a BMP.
2004-04-03 larwe created
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

#include <linux/videodev.h>
#include “bmplib.h”
/*
Demonstration main function
*/
int main(int _argc, char *_argv[])
{
BMINFO bi;
BLERR status;
unsigned char *capbuffer;
struct video_capability vc;
struct video_picture vp;
struct video_window vw;
int video, rc;
if (_argc < 2) {
printf(“Usage : vidcap filename.bmp\n”
“Captures one frame from /dev/video0 to filename.bmp\n”);
return -1;
}
printf(“Opening /dev/video0... “);
fflush(NULL);
video = open(“/dev/video0”, O_RDWR);
if (video == -1) {
printf(“Cannot open, aborting.\n”);
return -1;
}
printf(“OK.\nGetting device capabilities... “);
// Ascertain and display capture device properties
rc = ioctl(video, VIDIOCGCAP, &vc);
if (rc) {
printf(“VIDIOCGCAP failed, aborting.”);
return -1;
}
printf(“OK.\n”);
printf(“Name : ‘%s’\n”
“Channels : %d\n”
“Audios : %d\n”
“Size : %dx%d to %dx%d\n”, vc.name, vc.channels,
vc.audios, vc.minwidth, vc.minheight,
vc.maxwidth, vc.maxheight);

printf(“Capabilities : “);
if (vc.type & VID_TYPE_CAPTURE)
printf(“VID_TYPE_CAPTURE “);
if (vc.type & VID_TYPE_TUNER)
printf(“VID_TYPE_TUNER “);
if (vc.type & VID_TYPE_TELETEXT)
printf(“VID_TYPE_TELETEXT “);
if (vc.type & VID_TYPE_OVERLAY)
printf(“VID_TYPE_OVERLAY “);
if (vc.type & VID_TYPE_CHROMAKEY)
printf(“VID_TYPE_CHROMAKEY “);
if (vc.type & VID_TYPE_CLIPPING)
printf(“VID_TYPE_CLIPPING “);
if (vc.type & VID_TYPE_FRAMERAM)
printf(“VID_TYPE_FRAMERAM “);
if (vc.type & VID_TYPE_SCALES)
printf(“VID_TYPE_SCALES “);
if (vc.type & VID_TYPE_MONOCHROME)
printf(“VID_TYPE_MONOCHROME “);
if (vc.type & VID_TYPE_SUBCAPTURE)
printf(“VID_TYPE_SUBCAPTURE “);
printf(“\n”);
printf(“Getting image properties... “);
rc = ioctl(video, VIDIOCGPICT, &vp);
if (rc) {
printf(“VIDIOCGPICT failed, aborting.”);
return -1;
}
printf(“OK.\n”);
if (vp.palette != VIDEO_PALETTE_RGB24) {
// Attempt to set RGB24 palette
printf(“Attempting to set RGB24 palette... “);
vp.palette = VIDEO_PALETTE_RGB24;
rc = ioctl(video, VIDIOCSPICT, &vp);
if (rc) {
printf(“VIDIOCSPICT failed, aborting.\n”);
return -1;
}

rc = ioctl(video, VIDIOCGPICT, &vp);
if (rc) {
printf(“VIDIOCGPICT failed, aborting.\n”);
return -1;
}
if (vp.palette != VIDEO_PALETTE_RGB24) {
printf(“Device does not support RGB24 palette, aborting.\
n”);
return -1;
}
printf(“OK.\n”);
}
printf(“Brightness : %d\n”
“Hue : %d\n”
“Color : %d\n”
“Contrast : %d\n”
“Whiteness : %d\n”
“Depth : %d\n”,
vp.brightness, vp.hue, vp.colour, vp.contrast, vp.whiteness,
vp.depth, vp.palette);
printf(“Palette : “);
switch(vp.palette) {
case VIDEO_PALETTE_GREY: printf(“VIDEO_PALETTE_GREY”); break;
case VIDEO_PALETTE_HI240: printf(“VIDEO_PALETTE_HI240”); break;
case VIDEO_PALETTE_RGB565: printf(“VIDEO_PALETTE_RGB565”); break;
case VIDEO_PALETTE_RGB555: printf(“VIDEO_PALETTE_RGB555”); break;
case VIDEO_PALETTE_RGB24: printf(“VIDEO_PALETTE_RGB24”); break;
case VIDEO_PALETTE_RGB32: printf(“VIDEO_PALETTE_RGB32”); break;
case VIDEO_PALETTE_YUV422: printf(“VIDEO_PALETTE_YUV422”); break;
case VIDEO_PALETTE_YUYV: printf(“VIDEO_PALETTE_YUYV”); break;
case VIDEO_PALETTE_UYVY: printf(“VIDEO_PALETTE_UYVY”); break;
case VIDEO_PALETTE_YUV420: printf(“VIDEO_PALETTE_YUV420”); break;
case VIDEO_PALETTE_YUV411: printf(“VIDEO_PALETTE_YUV411”); break;
case VIDEO_PALETTE_RAW: printf(“VIDEO_PALETTE_RAW (BT848)”);
break;
case VIDEO_PALETTE_YUV422P: printf(“VIDEO_PALETTE_YUV422P”);break;
case VIDEO_PALETTE_YUV411P: printf(“VIDEO_PALETTE_YUV411P”);break;
default: printf(“Unrecognized”);
}
printf(“\n”);

if (vp.palette != VIDEO_PALETTE_RGB24 && vp.palette != VIDEO_PAL-
ETTE_RGB32) {
printf(“This program supports ONLY VIDEO_PALETTE_RGB24 and
VIDEO_PALETTE_RGB32.\n”);
return -1;
}
// Set window
vw.x = 0;
vw.y = 0;
vw.width = vc.maxwidth;
vw.height = vc.maxheight;
vw.chromakey = 0;
vw.flags = 0;
vw.clips = NULL;
vw.clipcount = 0;
printf(“Setting video capture window... “);
rc = ioctl(video, VIDIOCSWIN, &vw);
if (rc) {
printf(“Failed, aborting.\n”);
return -1;
}
printf(“OK.\n”);
printf(“Querying video capture window... “);
rc = ioctl(video, VIDIOCGWIN, &vw);
if (rc) {
printf(“Failed, aborting.\n”);
return -1;
}
printf(“OK, window size is %dx%d.\n”, vw.width, vw.height);
// Allocate RAM for capture buffer. At MOST we need 32 bits per
pixel.
capbuffer = malloc(vw.width * vw.height * 4);
if (capbuffer == NULL) {
printf(“Error allocating memory for capture buffer!\n”);
return -1;
}
// Capture an image using the read() interface. This is potential-
ly unsupported.
printf(“Reading buffer... “);
if (vp.palette == VIDEO_PALETTE_RGB24)
read(video, capbuffer, vw.width * vw.height * 3);

else if (vp.palette == VIDEO_PALETTE_RGB32)
read(video, capbuffer, vw.width * vw.height * 4);
printf(“OK.\n”);
printf(“Closing /dev/video0... “);
close(video);
printf(“OK.\n”);
// For RGB32, we need to convert the image down to RGB24.
if (vp.palette == VIDEO_PALETTE_RGB32) {
// BUGBUG - Not implemented yet!
printf(“CONVERSION NOT IMPLEMENTED.\n”);
return -1;
}
// Create overlying bitmap structure
bi.width = vw.width;
bi.height = vw.height;
bi.bitmapdata = capbuffer;
// Open output file
printf(“Saving output file... “);
fflush(NULL);
bi.fd = open(_argv[1], O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
if (bi.fd <= 0) {
printf(“Can’t open output file.\n”);
return -1;
}
status = BL_Save_Bitmap(&bi);
close(bi.fd);
printf(“Returncode %d\n”, status);
}

but under the /DEV directory I can't find any /DEV/VIDEO0 device , so where is the problem?
In the LINUX kernel source code included in the OLIMEX CD there are the sources of VIDEO4LINUX . If I recompile from scratch the Kernel ( 2.6.23 ) can I fix the problem?
I'm a beginner with Linux in general , so could some more experienced user tell me please where I'm wrong ?
Thank you very very much.


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Wed Apr 01, 2009 8:51 am 
Offline

Joined: Wed Apr 01, 2009 7:45 am
Posts: 20
Location: INDIA
thanks to at91s,
i am trying to make webcam to work on at91sam board. i got a problem and i searched the forum.
i got this thread talking same as my problem.

to make web cam to work on sbc what modules i need to load or to include in the kernel.
i tried to make
compat_ioctl32.ko
v4l1-compat.ko
v4l2-common.ko
videodev.ko
but still when i plugs-in the camera it is not showing in /dev/video0
to make it to auto generate in /dev/video0 which modules i need to include in kernel.


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Wed Apr 01, 2009 5:16 pm 
Offline

Joined: Sat Jun 21, 2008 8:13 pm
Posts: 7
Hi , I've solved the problem downloading the 2.6.25 stable kernel from www.kernel.org , patching and compiling it , and enabling the v4linux support ; adding the driver for omnivision usb camera , and it worked for me. In fact , I've booted the board with success from a usb pendrive with the new kernel kernel attached to a usb 2.0 hub which hosted the webcam too.
As a rule of thumb , to discover the right driver you need , you can plug the usb camera on a linux pc (which is only a beefed up version of an embedded SBC) and giving in a terminal window the command "dmesg" , you can search on the end of the log , informations about the type of device you have plugged. You can try also to issue the command "lsusb".
Then it's only a matter of searching under the kernel configuration tree , which driver for v4linux usb devices you must enable in the compile process of the kernel in order to get working the camera on your board.
Good luck. :D


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Wed Apr 15, 2009 7:53 am 
Offline

Joined: Wed Apr 01, 2009 7:45 am
Posts: 20
Location: INDIA
once again a small doubt. i compiled a Linux version 2.6.20.1.the content of /proc/devices
Code:
/var/lib/tftpboot $ cat /proc/devices  | more
Character devices:
  1 mem
  2 pty
  3 ttyp
  4 /dev/vc/0
  4 tty
  4 ttyS
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  7 vcs
10 misc
13 input
21 sg
29 fb
81 video4linux
128 ptm
136 pts
166 ttyACM
180 usb
188 ttyUSB
189 usb_device
--More--
Character devices:
  1 mem
  2 pty
  3 ttyp
  4 /dev/vc/0
  4 tty
  4 ttyS
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  7 vcs
10 misc
13 input
21 sg
29 fb
81 video4linux
128 ptm
136 pts
166 ttyACM
180 usb
188 ttyUSB
189 usb_device
212 DVB
--More--
212 DVB
254 usb_endpoint

Block devices:
  1 ramdisk
  8 sd
65 sd
66 sd
67 sd
68 sd
69 sd
70 sd
71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
180 ub
254 mmc
/var/lib/tftpboot $

as from Character devices: section
81 video4linux

i connected a uvc class camera and how to use it. my application needs a /dev/video0 file to access.
when i executes app like
Code:
/var/lib/tftpboot $ ./uvccapture -t10 -q60 -w -v
Using videodevice: /dev/video0
Saving images to: snap.jpg
Image size: 320x240
Taking snapshot every 10 seconds
Taking images using mmap
ERROR opening V4L interface
: No such device or address
/var/lib/tftpboot $


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Thu Apr 23, 2009 8:06 am 
Offline

Joined: Wed Apr 01, 2009 7:45 am
Posts: 20
Location: INDIA
Dear caccolillo,
am using UVC class camera and i downloaded some application to capture image from camera from http://www.quickcamteam.net/software/li ... 2-software
i downloaded uvccapture from above URL.
when i executing it on my desktop it is perfectly working. then i cross-compiled the dependencies jpeglib and then linked this libjpeg.a to uvccapture.
the output when i executed on my desktop
Code:
amarender@amarender-desktop:~$ sudo mknod /dev/video0 c 81 0
amarender@amarender-desktop:~$ sudo chmod 666 /dev/video0
amarender@amarender-desktop:~$ /home/amarender/Desktop/uvccapture-0.5/uvccapture -q60 -x680 -y480 -t10 -w -v
Using videodevice: /dev/video0
Saving images to: snap.jpg
Image size: 680x480
Taking snapshot every 10 seconds
Taking images using mmap
format asked unavailable get width 640 height 480
going to mmap
length: 614400 offset: 0
Buffer mapped at address 0xb7e72000.
length: 614400 offset: 614400
Buffer mapped at address 0xb7ddc000.
length: 614400 offset: 1228800
Buffer mapped at address 0xb7d46000.
length: 614400 offset: 1843200
Buffer mapped at address 0xb7cb0000.
length: 614400 offset: 2457600
Buffer mapped at address 0xb7c1a000.
length: 614400 offset: 3072000
Buffer mapped at address 0xb7b84000.
length: 614400 offset: 3686400
Buffer mapped at address 0xb7aee000.
length: 614400 offset: 4300800
Buffer mapped at address 0xb7a58000.
length: 614400 offset: 4915200
Buffer mapped at address 0xb79c2000.
length: 614400 offset: 5529600
Buffer mapped at address 0xb792c000.
length: 614400 offset: 6144000
Buffer mapped at address 0xb7896000.
length: 614400 offset: 6758400
Buffer mapped at address 0xb7800000.
length: 614400 offset: 7372800
Buffer mapped at address 0xb776a000.
length: 614400 offset: 7987200
Buffer mapped at address 0xb76d4000.
length: 614400 offset: 8601600
Buffer mapped at address 0xb763e000.
length: 614400 offset: 9216000
Buffer mapped at address 0xb75a8000.
Resetting camera settings
Camera brightness level is 0
Camera contrast level is 10
Camera saturation level is 4
Camera gain level is 32
Saving image to: snap.jpg
^CExiting...
amarender@amarender-desktop:~$



but when i execute on my at91sam9260 board
Code:


/tmp $ mknod /dev/video0 c 81 0

/tmp $ chmod 666 /dev/video0

/tmp $ ./uvc
/tmp $ ./uvccap~1 -q60 -x680 -y480 -t10 -w -v

Using videodevice: /dev/video0

Saving images to: snap.jpg

Image size: 680x480

Taking snapshot every 10 seconds

Taking images using mmap

going to mmap

length: 655360 offset: 0

Unable to map buffer (22)

Init v4L2 failed !! exit fatal

/tmp $

i figured that the problem is at mmap().

from above post you are using some other program to do same thing . can you give me the package.


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Tue Apr 28, 2009 9:35 am 
Offline

Joined: Wed Apr 01, 2009 7:45 am
Posts: 20
Location: INDIA
finnaly uvc web cam working . but hte problem is with the resolution. now it is limited to 320*240. but the same camera gives 640*480 resolution on my desktop. how can i rectify this.
/tmp $ uname -a

Linux uclibc 2.6.27 #8 Mon Apr 27 17:35:08 IST 2009 armv5tejl unknown

/tmp $ df -h

Filesystem Size Used Available Use% Mounted on

/dev/ram0 7.1M 4.5M 2.6M 64% /

tmpfs 29.8M 104.0k 29.7M 0% /tmp

/tmp $


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Tue Apr 28, 2009 11:49 am 
Offline

Joined: Sat Jun 21, 2008 8:13 pm
Posts: 7
amarendermail wrote:
Dear caccolillo,
am using UVC class camera and i downloaded some application to capture image from camera from http://www.quickcamteam.net/software/li ... 2-software
i downloaded uvccapture from above URL.
when i executing it on my desktop it is perfectly working. then i cross-compiled the dependencies jpeglib and then linked this libjpeg.a to uvccapture.
the output when i executed on my desktop
Code:
amarender@amarender-desktop:~$ sudo mknod /dev/video0 c 81 0
amarender@amarender-desktop:~$ sudo chmod 666 /dev/video0
amarender@amarender-desktop:~$ /home/amarender/Desktop/uvccapture-0.5/uvccapture -q60 -x680 -y480 -t10 -w -v
Using videodevice: /dev/video0
Saving images to: snap.jpg
Image size: 680x480
Taking snapshot every 10 seconds
Taking images using mmap
format asked unavailable get width 640 height 480
going to mmap
length: 614400 offset: 0
Buffer mapped at address 0xb7e72000.
length: 614400 offset: 614400
Buffer mapped at address 0xb7ddc000.
length: 614400 offset: 1228800
Buffer mapped at address 0xb7d46000.
length: 614400 offset: 1843200
Buffer mapped at address 0xb7cb0000.
length: 614400 offset: 2457600
Buffer mapped at address 0xb7c1a000.
length: 614400 offset: 3072000
Buffer mapped at address 0xb7b84000.
length: 614400 offset: 3686400
Buffer mapped at address 0xb7aee000.
length: 614400 offset: 4300800
Buffer mapped at address 0xb7a58000.
length: 614400 offset: 4915200
Buffer mapped at address 0xb79c2000.
length: 614400 offset: 5529600
Buffer mapped at address 0xb792c000.
length: 614400 offset: 6144000
Buffer mapped at address 0xb7896000.
length: 614400 offset: 6758400
Buffer mapped at address 0xb7800000.
length: 614400 offset: 7372800
Buffer mapped at address 0xb776a000.
length: 614400 offset: 7987200
Buffer mapped at address 0xb76d4000.
length: 614400 offset: 8601600
Buffer mapped at address 0xb763e000.
length: 614400 offset: 9216000
Buffer mapped at address 0xb75a8000.
Resetting camera settings
Camera brightness level is 0
Camera contrast level is 10
Camera saturation level is 4
Camera gain level is 32
Saving image to: snap.jpg
^CExiting...
amarender@amarender-desktop:~$



but when i execute on my at91sam9260 board
Code:


/tmp $ mknod /dev/video0 c 81 0

/tmp $ chmod 666 /dev/video0

/tmp $ ./uvc
/tmp $ ./uvccap~1 -q60 -x680 -y480 -t10 -w -v

Using videodevice: /dev/video0

Saving images to: snap.jpg

Image size: 680x480

Taking snapshot every 10 seconds

Taking images using mmap

going to mmap

length: 655360 offset: 0

Unable to map buffer (22)

Init v4L2 failed !! exit fatal

/tmp $

i figured that the problem is at mmap().

from above post you are using some other program to do same thing . can you give me the package.







I apologize for the delay , but I was a little bit busy with my college examinations. Sorry.
Try this code:




/* wcggrabber - a v4l (version 1) image grabber that can use the UYVY palette
* copyright (C) 2005-2006 by Erik Auerswald <auerswal@unix-ag.uni-kl.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/* Video4Linux (webcam) image grabber
*
* based on vgrabber.c from Phil Blundell <philb@gnu.org>
* source: http://www.tazenda.demon.co.uk/phil/vgrabber.c
* some info: http://www.tazenda.demon.co.uk/phil/v4l.html
* and yuv2ppm.c by Scott Scriven <toykeeper@cheerful.com>
* source: http://www.fourcc.org/yuv2ppm.c
* some info: http://www.fourcc.org/fccyvrgb.php
*
* modified to support Creative WebCam Go without postprocessing kernel module
* (see http://www.linux-projects.org/modules/m ... iewcat.php)
* and allow the setting of image parameters
* tested with Creative WebCam Go (W996[87]CF JPEG USB Dual Mode Camera Chip)
* and MIRO PCTV pro (Bt848)
*/

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <getopt.h>

#include <linux/types.h>
#include <linux/videodev.h>

#define DEFAULT_FILE "/dev/video0"
#define DEFAULT_OUTFILE "./FRAME" /* stdout */
#define PROGNAME "wcggrabber"
#define VERSION "1.6.1"
#define MAX_BRIGHTNESS_LOOPS 100
#define RGB555_DEFAULT_OFFSET 1 /* ignore most significant bit */
#define MAX_IMAGE_SIZE_NAME_LENGTH 5

/* Stole this from tvset.c */

#define READ_VIDEO_PIXEL(buf, format, depth, r, g, b) \
{ \
switch (format) \
{ \
case VIDEO_PALETTE_GREY: \
switch (depth) \
{ \
case 4: \
case 6: \
case 8: \
(r) = (g) = (b) = (*buf++ << 8);\
break; \
\
case 16: \
(r) = (g) = (b) = \
*((uint16_t *) buf); \
buf += 2; \
break; \
} \
break; \
\
\
case VIDEO_PALETTE_RGB565: \
{ \
uint16_t tmp = *(uint16_t *)buf; \
(r) = tmp&0xF800; \
(g) = (tmp<<5)&0xFC00; \
(b) = (tmp<<11)&0xF800; \
buf += 2; \
} \
break; \
\
case VIDEO_PALETTE_RGB555: \
{ \
uint16_t tmp = *(uint16_t *)buf; \
(r) = (tmp<<rgb555_offset)&0xF800; \
(g) = (tmp<<(5+rgb555_offset))&0xF800; \
(b) = (tmp<<(10+rgb555_offset))&0xF800; \
buf += 2; \
} \
break; \
\
case VIDEO_PALETTE_RGB24: \
(r) = buf[0] << 8; (g) = buf[1] << 8; \
(b) = buf[2] << 8; \
buf += 3; \
break; \
\
case VIDEO_PALETTE_RGB32: \
(r) = buf[0] << 8; (g) = buf[1] << 8; \
(b) = buf[2] << 8; \
buf += 4; \
break; \
\
\
default: \
fprintf(stderr, \
"Format %d not yet supported\n", \
format); \
} \
}

typedef struct image_size_s {
char name[MAX_IMAGE_SIZE_NAME_LENGTH+1];
uint32_t width;
uint32_t height;
} image_size_t;

image_size_t image_sizes[] = {
{"SQCIF", 128, 96},
{"", 0, 0}
};

/* found this in yuv2ppm.c */

static uint32_t yuv2rgb(int y, int u, int v)
{
uint32_t pixel32;
unsigned char *pixel = (unsigned char *)&pixel32;
int r, g, b;

#if 0
/*
One formula I found: (not the right one)

R = 1.164(Y - 16) + 1.596(Cr - 128)
G = 1.164(Y - 16) - 0.813(Cr - 128) - 0.391(Cb - 128)
B = 1.164(Y - 16) + 2.018(Cb - 128)
*/

r = (1.164 * (y - 16))
+ (2.018 * (v - 128));
g = (1.164 * (y - 16))
- (0.813 * (u - 128))
- (0.391 * (v - 128));
b = (1.164 * (y - 16))
+ (1.596 * (u - 128));
#else
/*
Another formula I found: (seems to work)

R = Y + 1.370705 (V-128)
G = Y - 0.698001 (V-128) - 0.337633 (U-128)
B = Y + 1.732446 (U-128)
*/

r = y + (1.370705 * (v-128));
g = y - (0.698001 * (v-128)) - (0.337633 * (u-128));
b = y + (1.732446 * (u-128));
#endif

/* Even with proper conversion, some values still need clipping. */
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;

/* Values only go from 0-220.. Why? */
pixel[0] = r * 220 / 256;
pixel[1] = g * 220 / 256;
pixel[2] = b * 220 / 256;
pixel[3] = 0;

/* Debug
printf("yuv2rgb(%i, %i, %i) -> %i, %i, %i (0x%x)\n",
y, u, v,
pixel[0], pixel[1], pixel[2],
pixel32);
*/

return pixel32;
}

/* end of yuv2ppm.c excerpt */

static int is_yuv(uint16_t palette)
{
return ((palette == VIDEO_PALETTE_YUV422) ||
(palette == VIDEO_PALETTE_YUYV) ||
(palette == VIDEO_PALETTE_UYVY) ||
(palette == VIDEO_PALETTE_YUV420) ||
(palette == VIDEO_PALETTE_YUV411) ||
(palette == VIDEO_PALETTE_YUV422P) ||
(palette == VIDEO_PALETTE_YUV411P) ||
(palette == VIDEO_PALETTE_YUV420P) ||
(palette == VIDEO_PALETTE_YUV410P));
}

static int get_brightness_adj(unsigned char *image, long size, int *brightness, int d)
{
long i, tot = 0;
for (i=0;i<size*d;i++)
tot += image[i];
*brightness = (128 - tot/(size*3))/3;
return !((tot/(size*3)) >= 126 && (tot/(size*3)) <= 130);
}

/* combine red, green and blue values to an RGBA value */
static uint32_t mk_pixel32(int r, int g, int b)
{
uint32_t pixel32;
unsigned char *pixels = (unsigned char *)&pixel32;

pixels[0]=r;
pixels[1]=g;
pixels[2]=b;
pixels[3]=0;
return pixel32;
}

/* parse an RGB mapping given as a string */
typedef struct rgb_map_s {
short r;
short g;
short b;
} rgb_map_t;

static int parse_rgb(const char *s, rgb_map_t *map)
{
int i;

if(strlen(s) != 3) {
return 0;
}
if((!(index(s, 'r')) && !(index(s, 'R'))) ||
(!(index(s, 'g')) && !(index(s, 'G'))) ||
(!(index(s, 'b')) && !(index(s, 'B')))) {
return 0;
}
for(i=0; i<3; i++) {
if(tolower(s[i]) == 'r') {
map->r = i;
} else if(tolower(s[i]) == 'g') {
map->g = i;
} else {
map->b = i;
}
}
return 1;
}

/* write a pixel to file */
static void write_pixel32(FILE *f, uint32_t pixel32, rgb_map_t map)
{
unsigned char *pixels = (unsigned char *)&pixel32;
if(!f) return;
fputc(pixels[map.r], f);
fputc(pixels[map.g], f);
fputc(pixels[map.b], f);
}

/* write a greyscale pixel to file */
static void write_byte(FILE *f, unsigned char pixel)
{
if(!f) return;
fputc(pixel, f);
}

/* parse string describing image size */
static int parse_size(const char *s, uint32_t *width, uint32_t *height)
{
int i;
char *tmp_s;
char *tmp_cp;

/* check if a known size is used */
for(i=0; image_sizes[i].name[0]; i++) {
if(strcasecmp(s, image_sizes[i].name) == 0) {
*width = image_sizes[i].width;
*height = image_sizes[i].height;
return 1;
}
}

/* is size given in WIDHTxHEIGHT? */
tmp_s = strdup(s);
if((tmp_cp = index(tmp_s, 'x'))) {
*tmp_cp = '\0';
tmp_cp++;
*width = atoi(tmp_s);
*height = atoi(tmp_cp);
free(tmp_s);
return 1;
} else {
return 0;
}
}

/* print queried capabilities */
static void print_capabilities(struct video_capability *cap,
struct video_channel **vchan, char *devicename)
{
int i; /* iterator */

/* name */
fprintf(stderr, " capabilities of \"%s\" (%s):\n", cap->name, devicename);
/* type of device */
if(cap->type & VID_TYPE_CAPTURE)
fprintf(stderr, " VID_TYPE_CAPTURE\n");
if(cap->type & VID_TYPE_TUNER)
fprintf(stderr, " VID_TYPE_TUNER\n");
if(cap->type & VID_TYPE_TELETEXT)
fprintf(stderr, " VID_TYPE_TELETEXT\n");
if(cap->type & VID_TYPE_OVERLAY)
fprintf(stderr, " VID_TYPE_OVERLAY\n");
if(cap->type & VID_TYPE_CHROMAKEY)
fprintf(stderr, " VID_TYPE_CHROMAKEY\n");
if(cap->type & VID_TYPE_CLIPPING)
fprintf(stderr, " VID_TYPE_CLIPPING\n");
if(cap->type & VID_TYPE_FRAMERAM)
fprintf(stderr, " VID_TYPE_FRAMERAM\n");
if(cap->type & VID_TYPE_SCALES)
fprintf(stderr, " VID_TYPE_SCALES\n");
if(cap->type & VID_TYPE_MONOCHROME)
fprintf(stderr, " VID_TYPE_MONOCHROME\n");
if(cap->type & VID_TYPE_SUBCAPTURE)
fprintf(stderr, " VID_TYPE_SUBCAPTURE\n");
if(cap->type & VID_TYPE_MPEG_DECODER)
fprintf(stderr, " VID_TYPE_MPEG_DECODER\n");
if(cap->type & VID_TYPE_MPEG_ENCODER)
fprintf(stderr, " VID_TYPE_MPEG_ENCODER\n");
if(cap->type & VID_TYPE_MJPEG_DECODER)
fprintf(stderr, " VID_TYPE_MJPEG_DECODER\n");
if(cap->type & VID_TYPE_MJPEG_ENCODER)
fprintf(stderr, " VID_TYPE_MJPEG_ENCODER\n");
/* number of channels */
fprintf(stderr, " number of channels: %d\n", cap->channels);
/* channel names */
for(i=0; i<cap->channels; i++) {
fprintf(stderr, " channel %d: %s\n", i, vchan[i]->name);
}
/* number of audio devices */
fprintf(stderr, " number of audio devices: %d\n", cap->audios);
/* minimum and maximum image size */
fprintf(stderr, " image size: ");
fprintf(stderr, "%d <= width <= %d, %d <= height <= %d\n", cap->minwidth,
cap->maxwidth, cap->minheight, cap->maxheight);
}

static void print_window_settings(struct video_window *win)
{
fprintf(stderr, " coordinates: x=%u, y=%u\n", win->x, win->y);
fprintf(stderr, " size: %ux%u\n", win->width, win->height);
fprintf(stderr, " chromakey: %u\n", win->chromakey);
}

static void print_image_properties(struct video_picture *vpic)
{
fprintf(stderr, " brightness: %u\n", vpic->brightness);
fprintf(stderr, " hue: %u\n", vpic->hue);
fprintf(stderr, " colour: %u\n", vpic->colour);
fprintf(stderr, " contrast: %u\n", vpic->contrast);
fprintf(stderr, " whiteness: %u (only for b/w capturing)\n",vpic->whiteness);
fprintf(stderr, " depth: %u\n", vpic->depth);
fprintf(stderr, " palette: ");
switch(vpic->palette) {
case VIDEO_PALETTE_GREY: fprintf(stderr, "VIDEO_PALETTE_GREY"); break;
case VIDEO_PALETTE_HI240: fprintf(stderr, "VIDEO_PALETTE_HI240"); break;
case VIDEO_PALETTE_RGB565: fprintf(stderr, "VIDEO_PALETTE_RGB565"); break;
case VIDEO_PALETTE_RGB24: fprintf(stderr, "VIDEO_PALETTE_RGB24"); break;
case VIDEO_PALETTE_RGB32: fprintf(stderr, "VIDEO_PALETTE_RGB32"); break;
case VIDEO_PALETTE_RGB555: fprintf(stderr, "VIDEO_PALETTE_RGB555"); break;
case VIDEO_PALETTE_YUV422: fprintf(stderr, "VIDEO_PALETTE_YUV422"); break;
case VIDEO_PALETTE_YUYV: fprintf(stderr, "VIDEO_PALETTE_YUYV"); break;
case VIDEO_PALETTE_UYVY: fprintf(stderr, "VIDEO_PALETTE_UYVY"); break;
case VIDEO_PALETTE_YUV420: fprintf(stderr, "VIDEO_PALETTE_YUV420"); break;
case VIDEO_PALETTE_YUV411: fprintf(stderr, "VIDEO_PALETTE_YUV411"); break;
case VIDEO_PALETTE_RAW: fprintf(stderr, "VIDEO_PALETTE_RAW"); break;
case VIDEO_PALETTE_YUV422P: fprintf(stderr,"VIDEO_PALETTE_YUV422P"); break;
case VIDEO_PALETTE_YUV411P: fprintf(stderr,"VIDEO_PALETTE_YUV411P"); break;
case VIDEO_PALETTE_YUV420P: fprintf(stderr,"VIDEO_PALETTE_YUV420P"); break;
case VIDEO_PALETTE_YUV410P: fprintf(stderr,"VIDEO_PALETTE_YUV410P"); break;
break;
default: fprintf(stderr, "unknown palette"); break;
}
fprintf(stderr, " (%u)\n", vpic->palette);
}

static void print_usage(const char *programname)
{
fprintf(stderr, "Usage: %s [OPTION]...\n", programname);
fprintf(stderr, "without any options an image is written to stdout using "
"current device settings\n");
fprintf(stderr, "\nOptions:\n");
fprintf(stderr, " -h|--help print this help\n");
fprintf(stderr, " -V|--version print program version"
" number\n");
fprintf(stderr, " -v|--verbose verbose program execution\n");
fprintf(stderr, " -q|--quiet quiet program execution\n");
fprintf(stderr, " -i|--info-only query capabilities of video "
"device and exit\n");
fprintf(stderr, " -s|--set-only set device parameters and "
"exit\n");
fprintf(stderr, " -f|--file|-o|--out-file=FILE write output to FILE (- for "
"stdout)\n");
fprintf(stderr, " -d|--device=DEVICE specify video4linux"
" DEVICE\n");
fprintf(stderr, " -S|--size=WIDTHxHEIGHT set image WIDTH and"
" HEIGHT\n");
fprintf(stderr, " -S|--size=KEYWORD set image size described by"
" KEYWORD\n");
fprintf(stderr, " (--size=help for list)\n");
fprintf(stderr, " -M|--max-size set maximum supported image"
" size (obsolete)\n");
fprintf(stderr, " -I|--min-size set minimum supported image"
" size (obsolete)\n");
fprintf(stderr, " -b|--brightness=BRIGHTNESS set BRIGHTNESS\n");
fprintf(stderr, " -H|--hue=HUE set HUE\n");
fprintf(stderr, " -c|--colour=COLOUR set COLOUR\n");
fprintf(stderr, " -C|--contrast=CONTRAST set CONTRAST\n");
fprintf(stderr, " -w|--whiteness=WHITENESS set WHITENESS"
" (monochrome only)\n");
fprintf(stderr, " -p|--palette=PALETTE set capture image PALETTE\n");
fprintf(stderr, " (--palette=help for list)\n");
fprintf(stderr, " -D|--depth=DEPTH set capture image DEPTH\n");
fprintf(stderr, " -n|--channel=NUMBER set source channel NUMBER\n");
fprintf(stderr, " -a|--auto-bright use vgrabber's automatic"
" RGB brightness adjust\n");
fprintf(stderr, " -t|--max-tries=NUMBER maximum NUMBER of tries for"
" RGB brightness adjust\n");
fprintf(stderr, " -R|--rgb-map=MAP mapping of red, green, and"
" blue values\n");
fprintf(stderr, " MAP = RGB | RBG | GRB | GBR |"
" BGR | BRG\n");
fprintf(stderr, " -g|--swap-gb swap green and blue bytes"
" in output (obsolete)\n");
fprintf(stderr, " -r|--swap-rb swap red and blue bytes"
" in output (obsolete)\n");
fprintf(stderr, " -l|--ignore-lsb ignore LSB in RGB555 mode\n");
fprintf(stderr, " -m|--ignore-msb ignore MSB in RGB555 mode\n");
fprintf(stderr, " -W|--write-raw write raw v4l output instead"
" of PPM\n");
fprintf(stderr, " -Y|--lum-only write a greyscale image using"
" only Y value\n"
" (YUV palettes only)\n");
fprintf(stderr, "\nDefaults:\n");
fprintf(stderr, " write output to \"%s\"\n",
strcmp("-", DEFAULT_OUTFILE) == 0 ? "stdout" : DEFAULT_OUTFILE);
fprintf(stderr, " use v4l device \"" DEFAULT_FILE "\" for input\n");
fprintf(stderr, " ignore %s significant bit (%cSB) when using RGB555"
" palette\n", RGB555_DEFAULT_OFFSET ? "most" : "least",
RGB555_DEFAULT_OFFSET ? 'M' : 'L');
fprintf(stderr, " maximum number of tries for brightness adjustment is %d\n",
MAX_BRIGHTNESS_LOOPS);
}

static void print_version(const char *programname)
{
fprintf(stderr, "WebCam Go image grabber (%s) version " VERSION "\n",
programname);
fprintf(stderr, "Copyright (C) 2005-2006 by Erik Auerswald\n");
}

static void print_palette_help(void)
{
fprintf(stderr, "PALETTE is one of (case is ignored):\n");
fprintf(stderr, "GREY, HI240, RGB565, RGB24, RGB32, RGB555, YUV422, YUYV\n");
fprintf(stderr, "UYVY, YUV420, YUV411, RAW, YUV422P, YUV411P, YUV420P, "
"YUV410P\n");
}

static void print_image_size_help(void)
{
int i;
fprintf(stderr, "size KEYWORD is one of (case is ignored):\n");
for(i=0; image_sizes[i].name[0]; i++) {
fprintf(stderr, " %-*s for %4dx%-4d\n",
MAX_IMAGE_SIZE_NAME_LENGTH, image_sizes[i].name,
image_sizes[i].width, image_sizes[i].height);
}
fprintf(stderr, " min for minimum size supported by camera\n"
" max for maximum size supported by camera\n");
}

int main(int argc, char **argv)
{
/*** variable definitions ***/
int j; /* iterator */
int fd = -1;
FILE *ofd = NULL;
int f;
char *devicename;
char *outfilename;
struct video_capability cap;
struct video_window win;
struct video_picture vpic;
struct video_channel **vchan = NULL;

char palettes[17][8] =
{
{""}, {"GREY"}, {"HI240"}, {"RGB565"}, {"RGB24"}, {"RGB32"}, {"RGB555"},
{"YUV422"}, {"YUYV"}, {"UYVY"}, {"YUV420"}, {"YUV411"}, {"RAW"},
{"YUV422P"}, {"YUV411P"}, {"YUV420P"}, {"YUV410P"}
};

/* RGB and image data variables */
unsigned char *buffer, *src;
int r=0, g=0, b=0;
unsigned int i, src_depth;

/* UYVY to RGB conversion variables */
uint32_t pixel32 = 0;
int y=0, u=0, v=0;
int rgb555_offset = RGB555_DEFAULT_OFFSET;

/* image format variables */
int set_image_format = 0;
int32_t brightness = -1, hue = -1, colour = -1, contrast = -1,
whiteness = -1, depth = -1, palette = -1;
uint32_t width=0, height=0;
int channel = -1;

/* program operation flags */
int show_info = 0;
int set_only = 0;
int verbose = 0;
int quiet = 0;
int auto_bright = 0;
unsigned int max_tries = MAX_BRIGHTNESS_LOOPS;
int set_max_size = 0;
int set_min_size = 0;
rgb_map_t rgb_map = { 0, 1, 2 };
int write_raw = 0;
int lum_only = 0;

/*** begin of program code ***/
/* set default devicename and output filename */
devicename = strdup(DEFAULT_FILE);
outfilename = strdup(DEFAULT_OUTFILE);

/* initialize variables */
cap.name[0] = '\0';
cap.type = cap.channels = cap.audios = cap.maxwidth = cap.minwidth =
cap.maxheight = cap.minheight = 0;
win.x = win.y = win.width = win.height = win.chromakey = win.flags = 0;
vpic.brightness = vpic.hue = vpic.colour = vpic.contrast = vpic.whiteness =
vpic.depth = vpic.palette = 0;

while(1) {
int option_index = 0;
char c;
static struct option long_options[] = {
{ "file", 1, 0, 'f' }, /* filename for output */
{ "out-file", 1, 0, 'o' }, /* filename for output */
{ "device", 1, 0, 'd' }, /* v4l device */
{ "info-only", 0, 0, 'i' }, /* show device information */
{ "set-only", 0, 0, 's' }, /* set device parameters */
{ "help", 0, 0, 'h' }, /* print help */
{ "version", 0, 0, 'V' }, /* show version */
{ "verbose", 0, 0, 'v' }, /* verbose execution */
{ "quiet", 0, 0, 'q' }, /* quiet execution */
{ "brightness", 1, 0, 'b' }, /* set brightness */
{ "hue", 1, 0, 'H' }, /* set hue */
{ "colour", 1, 0, 'c' }, /* set colour */
{ "contrast", 1, 0, 'C' }, /* set contrast */
{ "whiteness", 1, 0, 'w' }, /* set whiteness */
{ "depth", 1, 0, 'D' }, /* set capture depth */
{ "channel", 1, 0, 'n' }, /* set source channel */
{ "palette", 1, 0, 'p' }, /* set palette */
{ "size", 1, 0, 'S' }, /* set image size */
{ "max-size", 0, 0, 'M' }, /* set maximum supported image size */
{ "min-size", 0, 0, 'I' }, /* set minimum supported image size */
{ "auto-bright", 0, 0, 'a' }, /* use automatic brightness adjust */
{ "max-tries", 1, 0, 't' }, /* max no of tries for brightness adj.*/
{ "swap-gb", 0, 0, 'g' }, /* swap green and blue bytes */
{ "swap-rb", 0, 0, 'r' }, /* swap red and blue bytes */
{ "ignore-lsb", 0, 0, 'l' }, /* ignore LSB of RGB555 value */
{ "ignore-msb", 0, 0, 'm' }, /* ignore MSB of RGB555 value */
{ "rgb-map", 1, 0, 'R'}, /* where to find the RGB values */
{ "write-raw", 0, 0, 'W'}, /* raw v4l output */
{ "lum-only", 0, 0, 'Y'}, /* greyscale from Y value */
{ 0, 0, 0, 0 } /* terminate long options */
};

c = getopt_long(argc,argv,"f:o:d:ishVvqb:H:c:C:w:D:n:p:S:MIat:grlmiR:WY",
long_options, &option_index);
signed short int app; //*************
app=c; //*************
if(app == -1) //*************
break;

switch(c) {
// case 'f':
// case 'o':
// if(optarg) {
// free(outfilename);
// outfilename = strdup(optarg);
// }
// break;

// case 'd':
// if(optarg) {
// free(devicename);
// devicename = strdup(optarg);
// }
// break;

// case 'i':
// show_info = 1;
// break;

// case 's':
// set_only = 1;
// break;

// case 'h':
// print_version(PROGNAME); fprintf(stderr, "\n");
// print_usage(PROGNAME);
// exit(EXIT_SUCCESS);
// break;

// case 'V':
// print_version(PROGNAME);
// exit(EXIT_SUCCESS);
// break;

// case 'v':
// verbose = 1;
// quiet = 0;
// break;

// case 'q':
// quiet = 1;
// verbose = 0;
// break;

// case 'b':
// if(optarg) {
// brightness = (int32_t) atoi(optarg);
// set_image_format = 1;
// }
// break;

// case 'H':
// if(optarg) {
// hue = (int32_t) atoi(optarg);
// set_image_format = 1;
// }
// break;

// case 'c':
// if(optarg) {
// colour = (int32_t) atoi(optarg);
// set_image_format = 1;
// }
// break;

// case 'C':
// if(optarg) {
// contrast = (int32_t) atoi(optarg);
// set_image_format = 1;
// }
// break;

// case 'w':
// if(optarg) {
// whiteness = (int32_t) atoi(optarg);
// set_image_format = 1;
// }
// break;

// case 'D':
// if(optarg) {
// depth = (int32_t) atoi(optarg);
// set_image_format = 1;
// }
// break;

// case 'n':
// channel = atoi(optarg);
// break;

case 'p':
if(optarg) {
set_image_format = 1;
if(strcasecmp("grey", optarg) == 0) {
palette = VIDEO_PALETTE_GREY;
depth = 8;
}
else if(strcasecmp("hi240", optarg) == 0) {
palette = VIDEO_PALETTE_HI240;
depth = 8;
}
else if(strcasecmp("rgb565", optarg) == 0) {
palette = VIDEO_PALETTE_RGB565;
depth = 16;
}
else if(strcasecmp("rgb24", optarg) == 0) {
palette = VIDEO_PALETTE_RGB24;
depth = 24;
}
else if(strcasecmp("rgb32", optarg) == 0) {
palette = VIDEO_PALETTE_RGB32;
depth = 32;
}
else if(strcasecmp("rgb555", optarg) == 0) {
palette = VIDEO_PALETTE_RGB555;
depth = 16;
}
else if(strcasecmp("yuv422", optarg) == 0) {
palette = VIDEO_PALETTE_YUV422;
depth = 16;
}
else if(strcasecmp("yuyv", optarg) == 0) {
palette = VIDEO_PALETTE_YUYV;
depth = 16;
}
else if(strcasecmp("uyvy", optarg) == 0) {
palette = VIDEO_PALETTE_UYVY;
depth = 16;
}
else if(strcasecmp("yuv420", optarg) == 0) {
palette = VIDEO_PALETTE_YUV420;
depth = 12; /* this is a guess... */
}
else if(strcasecmp("yuv411", optarg) == 0) {
palette = VIDEO_PALETTE_YUV411;
depth = 12; /* this is a guess... */
}
else if(strcasecmp("raw", optarg) == 0) {
palette = VIDEO_PALETTE_RAW;
depth = 8;
}
else if(strcasecmp("yuv422p", optarg) == 0) {
palette = VIDEO_PALETTE_YUV422P;
depth = 16;
}
else if(strcasecmp("yuv411p", optarg) == 0) {
palette = VIDEO_PALETTE_YUV411P;
depth = 12;
}
else if(strcasecmp("yuv420p", optarg) == 0) {
palette = VIDEO_PALETTE_YUV420P;
depth = 12;
}
else if(strcasecmp("yuv410p", optarg) == 0) {
palette = VIDEO_PALETTE_YUV410P;
depth = 9;
}
else if(strcasecmp("help", optarg) == 0) {
print_palette_help();
exit(EXIT_SUCCESS);
} else {
if(!quiet)
fprintf(stderr, "unknown palette %s\n", optarg);
print_palette_help();
exit(EXIT_FAILURE);
}
}
break;

case 'S':
if(optarg) {
printf("\n*************************** setto dimensioni ********************************************+\n");
if(strcasecmp(optarg, "help") == 0) {
printf("\n***** help\n");
print_image_size_help();
exit(EXIT_SUCCESS);
} else if(strcasecmp(optarg, "max") == 0) {
printf("\n***** max\n");
set_image_format = 1;
set_max_size = 1;
set_min_size = 0;
width = height = 0;
} else if(strcasecmp(optarg, "min") == 0) {
printf("\n***** min\n");
set_image_format = 1;
set_max_size = 0;
set_min_size = 1;
width = height = 0;
} else if(parse_size(optarg, &width, &height)) {
printf("\n***** free\n");
set_image_format = 1;
set_max_size = 0;
set_min_size = 0;
} else {
if(!quiet)
fprintf(stderr, "error: could not parse size argument \"%s\"\n",
optarg);
}
}
break;

case 'M':
set_image_format = 1;
set_max_size = 1;
set_min_size = 0;
width = height = 0;
if(!quiet) {
fprintf(stderr, "warning: option -M|--max-size is obsolete, use"
" --size=max instead\n");
}
break;

case 'I':
set_image_format = 1;
set_min_size = 1;
set_max_size = 0;
width = height = 0;
if(!quiet) {
fprintf(stderr, "warning: option -I|--min-size is obsolete, use"
" --size=min instead\n");
}
break;

case 'a':
auto_bright = 1;
break;

case 't':
if(optarg) {
int tmp_max_tries = atoi(optarg);
if(tmp_max_tries >= 0) {
max_tries = tmp_max_tries;
} else {
fprintf(stderr, "error: number of tries must be positive\n");
}
}
break;

case 'g':
parse_rgb("rbg", &rgb_map);
if(!quiet)
fprintf(stderr, "warning: option -g|--swap-gb is obsolete, use"
" --rgb-map RBG instead\n");
break;

case 'r':
parse_rgb("bgr", &rgb_map);
if(!quiet)
fprintf(stderr, "warning: option -r|--swap-rb is obsolete, use"
" --rgb-map BGR instead\n");
break;

case 'R':
if(optarg) {
if(!parse_rgb(optarg, &rgb_map)) {
fprintf(stderr, "error: could not parse %s as an RGB map\n",
optarg);
}
}
break;

case 'l':
rgb555_offset = 0;
break;

case 'm':
rgb555_offset = 1;
break;

case 'W':
write_raw = 1;
break;

// case 'Y':
// lum_only = 1;
// break;

case '?':
fprintf(stderr, "error: unknown option\n");
print_usage(PROGNAME);
exit(EXIT_FAILURE);
break;

default: /* should never be reached if getopt() works */
fprintf(stderr, "error: getopt() returned character 0x%x\n", c);
}
}


palette = VIDEO_PALETTE_GREY;
depth = 8;



if(optind < argc) {
fprintf(stderr, "unknown argument `%s'\n", argv[optind]);
print_usage(PROGNAME);
exit(EXIT_FAILURE);
}

/* print program version in verbose mode */
if(verbose)
print_version(PROGNAME);

/* open video device */
if(verbose)
fprintf(stderr, "opening video device...\n");
fd = open(devicename, O_RDONLY);
if (fd < 0) {
perror(devicename);
exit(EXIT_FAILURE);
}

/* query device capabilities */
if(verbose)
fprintf(stderr, "querying device capabilities...\n");
if (ioctl(fd, VIDIOCGCAP, &cap) < 0) {
perror("VIDIOGCAP");
if(!quiet)
fprintf(stderr, "(%s not a video4linux device?)\n", devicename);
close(fd);
exit(EXIT_FAILURE);
}

/* query channel information */
if(show_info || (channel>-1)) {
if(verbose)
fprintf(stderr, "querying channel information...\n");
if(!(vchan = calloc(cap.channels, sizeof(struct video_channel *)))) {
perror("calloc()");
close(fd);
exit(EXIT_FAILURE);
}
for(j=0; j<cap.channels; j++) {
if(verbose)
fprintf(stderr, "querying channel %d...\n", j);
if(!(vchan[j] = calloc(1, sizeof(struct video_channel)))) {
perror("calloc()");
close(fd);
exit(EXIT_FAILURE);
}
vchan[j]->channel = j;
if(ioctl(fd, VIDIOCGCHAN, vchan[j]) < 0) {
if(!quiet)
fprintf(stderr, "warning: could not query channel %d\n", j);
}
}
}

if(show_info)
print_capabilities(&cap, vchan, devicename);

/* query current window settings */
if(verbose)
fprintf(stderr, "querying current video window settings...\n");
if (ioctl(fd, VIDIOCGWIN, &win) < 0) {
perror("VIDIOCGWIN");
close(fd);
exit(EXIT_FAILURE);
}
if(show_info)
print_window_settings(&win);

/* query image properties */
if(verbose)
fprintf(stderr, "querying current image properties...\n");
if (ioctl(fd, VIDIOCGPICT, &vpic) < 0) {
perror("VIDIOCGPICT");
close(fd);
exit(EXIT_FAILURE);
}
if(show_info) {
print_image_properties(&vpic);
exit(EXIT_SUCCESS);
}

/* exit if device can not capture to memory */
if(!(cap.type & VID_TYPE_CAPTURE)) {
if(!quiet) {
fprintf(stderr, "error: video4linux device %s cannot capture to memory\n",
devicename);
}
exit(EXIT_FAILURE);
}
free(devicename); /* not needed any more */

/* set source channel */
if(channel > -1) {
if(channel < cap.channels) {
if(verbose)
fprintf(stderr, "selecting source channel %d (%s)...\n", channel,
vchan[channel]->name);
if(ioctl(fd, VIDIOCSCHAN, vchan[channel]) < 0) {
perror("VIDIOCSCHAN");
close(fd);
exit(EXIT_FAILURE);
}
if(verbose)
fprintf(stderr, " selected channel %d (%s)\n", channel,
vchan[channel]->name);
} else {
if(!quiet)
fprintf(stderr, "there is no channel %d (found %d channel%s)\n",
channel, cap.channels, (cap.channels == 1) ? "" : "s");
}
}

/* free memory used for channel descriptions */
if(vchan) {
for(j=0; j<cap.channels; j++) {
free(vchan[j]);
}
}

/* set image format */
if(set_image_format) {
if(set_max_size) {
if(verbose)
fprintf(stderr, "using maximum supported image size %ux%u...\n",
cap.maxwidth, cap.maxheight);
width = cap.maxwidth;
height = cap.maxheight;
}
if(set_min_size) {
if(verbose)
fprintf(stderr, "using minimum supported image size %ux%u...\n",
cap.minwidth, cap.minheight);
width = cap.minwidth;
height = cap.minheight;
}
if(width > 0) {
if((width >= (uint32_t) cap.minwidth) &&
(width <= (uint32_t) cap.maxwidth)) {
if(verbose)
fprintf(stderr, "setting image width %u...\n", width);
win.width = width;
} else if(!quiet) {
fprintf(stderr, "ignoring image width %u not in [%u,%u]\n", width,
cap.minwidth, cap.maxwidth);
}
}
if(height > 0) {
if((height >= (uint32_t) cap.minheight) &&
(height <= (uint32_t) cap.maxheight)) {
if(verbose)
fprintf(stderr, "setting image height %u...\n", height);
win.height = height;
} else if(!quiet) {
fprintf(stderr, "ignoring image height %u not in [%u,%u]\n", height,
cap.minheight, cap.maxheight);
}
}
if(brightness > -1) {
if(brightness <= 65535) {
if(verbose)
fprintf(stderr, "setting brightness %u...\n", brightness);
vpic.brightness = brightness;
} else if(!quiet) {
fprintf(stderr, "ignoring brightness %u > 65535\n", brightness);
}
}
if(hue > -1) {
if(hue <= 65535) {
if(verbose)
fprintf(stderr, "setting hue %u...\n", hue);
vpic.hue = hue;
} else if(!quiet) {
fprintf(stderr, "ignoring hue %u > 65535\n", hue);
}
}
if(colour > -1) {
if(colour <= 65535) {
if(verbose)
fprintf(stderr, "setting colour %u...\n", colour);
vpic.colour = colour;
} else if(!quiet) {
fprintf(stderr, "ignoring colour %u > 65535\n", colour);
}
}
if(contrast > -1) {
if(contrast <= 65535) {
if(verbose)
fprintf(stderr, "setting contrast %u...\n", contrast);
vpic.contrast = contrast;
} else if(!quiet) {
fprintf(stderr, "ignoring contrast %u > 65535\n", contrast);
}
}
if(whiteness > -1) {
if(whiteness <= 65535) {
if(verbose)
fprintf(stderr, "setting whiteness %u...\n", whiteness);
vpic.whiteness = whiteness;
} else if(!quiet) {
fprintf(stderr, "ignoring whiteness %u > 65535\n", whiteness);
}
}
if(depth > -1) {
if(depth <= 65535) {
if(verbose)
fprintf(stderr, "setting capture depth %u...\n", depth);
vpic.depth = depth;
} else if(!quiet) {
fprintf(stderr, "ignoring capture depth %u > 65535\n", depth);
}
}
if(palette > -1) {
if(palette <= VIDEO_PALETTE_YUV410P) { /* highest used palette */
if(verbose)
fprintf(stderr, "setting palette %s...\n", palettes[palette]);
vpic.palette = palette;
} else if(!quiet) {
fprintf(stderr, "ignoring palette %u > VIDEO_PALETTE_YUV410P\n",
palette);
}
}

/* set image size */
if((width > 0) || (height > 0)) {
if(verbose)
fprintf(stderr, "setting image size...\n");
if(ioctl(fd, VIDIOCSWIN, &win) < 0) {
perror("VIDIOCSWIN");
if(!quiet)
fprintf(stderr, "warning: could not set image size\n");
}

/* check result */
if(ioctl(fd, VIDIOCGWIN, &win) < 0) {
perror("VIDIOCGWIN");
if(!quiet)
fprintf(stderr, "error: could not read window settings, exiting\n");
exit(EXIT_FAILURE);
} else {
if(win.width != width) {
if(!quiet)
fprintf(stderr, "warning: set image width to %u\n", win.width);
} else if(verbose) {
fprintf(stderr, "successfully set image width %u\n", win.width);
}
if(win.height != height) {
if(!quiet)
fprintf(stderr, "warning: set image height to %u\n", win.height);
} else if(verbose) {
fprintf(stderr, "successfully set image height %u\n", win.height);
}
}
}

/* set image properties */
if(verbose)
fprintf(stderr, "setting image properties...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
perror("VIDIOCSPICT");
if(!quiet)
fprintf(stderr, "warning: could not set image properties\n");
}

/* check if request could be fulfilled */
if(ioctl(fd, VIDIOCGPICT, &vpic) < 0) {
perror("VIDIOCGPICT");
if(!quiet)
fprintf(stderr, "error: could not read image properties, exiting\n");
close(fd);
exit(EXIT_FAILURE);
} else {
if(brightness > -1) {
if(brightness != vpic.brightness) {
if(!quiet)
fprintf(stderr,"warning: set brightness to %u\n",vpic.brightness);
} else if(verbose) {
fprintf(stderr, "brightness successfully set to %u\n",
vpic.brightness);
}
}
if(hue > -1) {
if(hue != vpic.hue) {
if(!quiet)
fprintf(stderr,"warning: set hue to %u\n",vpic.hue);
} else if(verbose) {
fprintf(stderr, "hue successfully set to %u\n",
vpic.hue);
}
}
if(colour > -1) {
if(colour != vpic.colour) {
if(!quiet)
fprintf(stderr,"warning: set colour to %u\n",vpic.colour);
} else if(verbose) {
fprintf(stderr, "colour successfully set to %u\n",
vpic.colour);
}
}
if(contrast > -1) {
if(contrast != vpic.contrast) {
if(!quiet)
fprintf(stderr,"warning: set contrast to %u\n",vpic.contrast);
} else if(verbose) {
fprintf(stderr, "contrast successfully set to %u\n",
vpic.contrast);
}
}
if(whiteness > -1) {
if(whiteness != vpic.whiteness) {
if(!quiet)
fprintf(stderr,"warning: set whiteness to %u\n",vpic.whiteness);
} else if(verbose) {
fprintf(stderr, "whiteness successfully set to %u\n",
vpic.whiteness);
}
}
if(depth > -1) {
if(depth != vpic.depth) {
if(!quiet)
fprintf(stderr,"warning: set depth to %u\n",vpic.depth);
} else if(verbose) {
fprintf(stderr, "depth successfully set to %u\n",
vpic.depth);
}
}
if(palette > -1) {
if(palette != vpic.palette) {
if(!quiet)
fprintf(stderr, "warning: set palette to %s\n",
palettes[vpic.palette]);
} else if(verbose) {
fprintf(stderr, "palette successfully set to %s\n",
palettes[vpic.palette]);
}
}
}
}
if(set_only)
exit(EXIT_SUCCESS);

/* check if a usable palette can be set */
if((palette < 0) && !write_raw) {

/* check if current palette is usable */
switch(vpic.palette) {
case VIDEO_PALETTE_GREY:
case VIDEO_PALETTE_RGB24:
case VIDEO_PALETTE_RGB32:
case VIDEO_PALETTE_RGB565:
case VIDEO_PALETTE_RGB555:
case VIDEO_PALETTE_UYVY:
case VIDEO_PALETTE_YUYV:
case VIDEO_PALETTE_YUV422:
case VIDEO_PALETTE_YUV420:
case VIDEO_PALETTE_YUV422P:
case VIDEO_PALETTE_YUV411P:
case VIDEO_PALETTE_YUV420P:
case VIDEO_PALETTE_YUV410P:
if(verbose)
fprintf(stderr, "keeping current palette setting (%s)...\n",
palettes[vpic.palette]);
break;

default:
if(verbose)
fprintf(stderr, "cannot use current palette setting (%s)\n"
"trying to set a supported palette...\n",
palettes[vpic.palette]);

if (cap.type & VID_TYPE_MONOCHROME) {
vpic.depth=8;
vpic.palette=VIDEO_PALETTE_GREY; /* 8bit grey */
if(verbose)
fprintf(stderr, " trying 8 bit GREY...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.depth=6;
if(verbose)
fprintf(stderr, " trying 6 bit GREY...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.depth=4;
if(verbose)
fprintf(stderr, " trying 4 bit GREY...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
fprintf(stderr, "Unable to find a supported capture format.\n");
close(fd);
exit(EXIT_FAILURE);
}
}
}
} else {
vpic.depth=24;
vpic.palette=VIDEO_PALETTE_RGB24;
if(verbose)
fprintf(stderr, " trying RGB24...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.depth=32;
vpic.palette=VIDEO_PALETTE_RGB32;
if(verbose)
fprintf(stderr, " trying RGB32...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_RGB565;
vpic.depth=16;
if(verbose)
fprintf(stderr, " trying RGB565...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_RGB555;
vpic.depth=16;
if(verbose)
fprintf(stderr, " trying RGB555...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_UYVY;
vpic.depth=16;
if(verbose)
fprintf(stderr, " trying UYVY...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_YUYV;
vpic.depth=16;
if(verbose)
fprintf(stderr, " trying YUYV...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_YUV422;
vpic.depth=16;
if(verbose)
fprintf(stderr, " trying YUV422...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_YUV422P;
vpic.depth=16;
if(verbose)
fprintf(stderr, " trying YUV422P...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_YUV420;
vpic.depth=12;
if(verbose)
fprintf(stderr, " trying YUV420...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_YUV411P;
vpic.depth=12;
if(verbose)
fprintf(stderr, " trying YUV411P...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_YUV420P;
vpic.depth=12;
if(verbose)
fprintf(stderr, " trying YUV420P...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
vpic.palette=VIDEO_PALETTE_YUV410P;
vpic.depth=9;
if(verbose)
fprintf(stderr, " trying YUV410P...\n");
if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
fprintf(stderr, "\nUnable to find a supported"
" capture format.\n");
close(fd);
exit(EXIT_FAILURE);
}
}
}
}
}
}
}
}
}
}
}
}
}
break;
}
}
src_depth = vpic.depth;
if(verbose) {
fprintf(stderr, "using palette %s (depth %d bpp)\n", palettes[vpic.palette],
vpic.depth);
}
/* exit if palette can not be converted to image file */
if(!((vpic.palette == VIDEO_PALETTE_GREY) ||
(vpic.palette == VIDEO_PALETTE_RGB24) ||
(vpic.palette == VIDEO_PALETTE_RGB32) ||
(vpic.palette == VIDEO_PALETTE_RGB565) ||
(vpic.palette == VIDEO_PALETTE_RGB555) ||
(vpic.palette == VIDEO_PALETTE_UYVY) ||
(vpic.palette == VIDEO_PALETTE_YUV422) || /* seems to be same as YUYV */
(vpic.palette == VIDEO_PALETTE_YUV420) || /* seems same as YUV420P */
(vpic.palette == VIDEO_PALETTE_YUV422P) ||
(vpic.palette == VIDEO_PALETTE_YUV411P) ||
(vpic.palette == VIDEO_PALETTE_YUV420P) ||
(vpic.palette == VIDEO_PALETTE_YUV410P) ||
(vpic.palette == VIDEO_PALETTE_YUYV) ) && !write_raw) {
if(!quiet)
fprintf(stderr, "Palette %s not supported for capturing.\n",
palettes[vpic.palette]);
exit(EXIT_FAILURE);
}

if(verbose)
fprintf(stderr, "allocating buffer for image...\n");
buffer = malloc((win.width * win.height * src_depth)/8);
if (!buffer) {
fprintf(stderr, "out of memory.\n");
exit(EXIT_FAILURE);
}

/* adjust brightness when told so and using some RGB palette */
i = 0;
do {
int newbright;
size_t bytesread;
if(verbose)
fprintf(stderr, "capturing image...\n");
bytesread = read(fd, buffer, (win.width * win.height * src_depth)/8);
if(verbose)
fprintf(stderr, "read %d bytes\n", bytesread);
if((auto_bright) && (brightness < 0) &&
(vpic.palette!=VIDEO_PALETTE_UYVY)&&(vpic.palette!=VIDEO_PALETTE_YUYV)&&
(vpic.palette!=VIDEO_PALETTE_YUV422)) {
if(verbose)
fprintf(stderr, "adjusting brightness (try %u/%u)...\n",i+1,max_tries);
f = get_brightness_adj(buffer, win.width * win.height, &newbright,
src_depth/8);
if (f) {
vpic.brightness += (newbright << 8);
if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) {
perror("VIDIOSPICT");
break;
}
}
} else {
break;
}
i++;
} while (f && (i < max_tries));
close(fd);

if(verbose) {
fprintf(stderr, "writing image");
if(write_raw) {
fprintf(stderr, " as raw v4l %s data",
palettes[vpic.palette]);
} else if(lum_only || (vpic.palette == VIDEO_PALETTE_GREY)) {
fprintf(stderr, " in Netpbm PGM \"rawbits\" format");
} else {
fprintf(stderr, " in Netpbm PPM \"rawbits\" format");
}
fprintf(stderr, " to file %s...\n",
strcmp("-", outfilename) == 0 ? "/dev/stdout" : outfilename);
}
/* open output file */
if(strcmp("-", outfilename) == 0)
ofd = stdout;
else {
ofd = fopen(outfilename, "w");
if(ofd == NULL) {
perror(outfilename);
exit(EXIT_FAILURE);
}
}

/* write pgm or ppm header */
if(!write_raw) {
if((lum_only && is_yuv(vpic.palette)) ||
(vpic.palette == VIDEO_PALETTE_GREY)) {
fprintf(ofd, "P5\n%d %d 255\n", win.width, win.height);
} else {
fprintf(ofd, "P6\n%d %d 255\n", win.width, win.height);
}
}

src = buffer;

if(write_raw) {
fwrite(buffer, 1, (win.width * win.height * src_depth)/8, ofd);
} else {
for (i = 0; i < win.width * win.height; i++) {
if(!is_yuv(vpic.palette)) {
READ_VIDEO_PIXEL(src, vpic.palette, src_depth, r, g, b);
pixel32 = mk_pixel32(r>>8, g>>8, b>>8);
} else {
if(vpic.palette == VIDEO_PALETTE_UYVY) {
if(i==0) {
v = src[3];
}
if((i%2) == 0) {
u = src[0];
y = src[1];
src += 2; /* v from next 16bit word */
} else {
v = src[0];
y = src[1];
src += 2;
}
} else if((vpic.palette == VIDEO_PALETTE_YUYV) ||
(vpic.palette == VIDEO_PALETTE_YUV422)) {
if(i==0) {
v = src[4];
}
if((i%2) == 0) {
y = src[0];
u = src[1];
src += 2; /* v from next 16bit word */
} else {
y = src[0];
v = src[1];
src += 2;
}
}
else if(vpic.palette == VIDEO_PALETTE_YUV422P) {
y = buffer[i];
if(i == 0) {
src = buffer + (win.width*win.height);
}
u = src[(i/2)%(win.width/2)];
v = src[(win.width*win.height)/2 + (i/2)%(win.width/2)];
if(i && (i%(win.width*2) == 0)) {
src += win.width;
}
} else if(vpic.palette == VIDEO_PALETTE_YUV411P) {
y = buffer[i];
if(i == 0) {
src = buffer + (win.width*win.height);
}
u = src[(i/4)%(win.width/4)];
v = src[(win.width*win.height)/4 + (i/4)%(win.width/4)];
if(i && (i%(win.width) == 0)) {
src += win.width/4;
}
} else if((vpic.palette == VIDEO_PALETTE_YUV420P) ||
(vpic.palette == VIDEO_PALETTE_YUV420)) {
if(i == 0) {
src = buffer + (win.width*win.height);
}
y = buffer[i];
u = src[(i/2)%(win.width/2)];
v = src[(win.width*win.height)/4 + (i/2)%(win.width/2)];
if(i && (i%(win.width*4)) == 0) {
src += win.width;
}
} else if(vpic.palette == VIDEO_PALETTE_YUV410P) {
if(i == 0) {
src = buffer + (win.width*win.height);
}
y = buffer[i];
u = src[(i/4)%(win.width/4)];
v = src[(win.width*win.height)/16 + (i/4)%(win.width/4)];
if(i && (i%(win.width*4)) == 0) {
src += win.width/4;
}
}
if(!lum_only) {
pixel32 = yuv2rgb(y, u, v);
}
}
if(lum_only && is_yuv(vpic.palette)) {
write_byte(ofd, y&0xFF);
} else if(vpic.palette == VIDEO_PALETTE_GREY) {
write_byte(ofd, ((unsigned char *)&pixel32)[1]);
} else {
write_pixel32(ofd, pixel32, rgb_map);
}
}
}
fclose(ofd);
exit(EXIT_SUCCESS);
}



It's great , and is a "piece of cake" even on my cheap board.
It isn't mine and the author's name is written onto it.
If you're still in trouble try a google search with these keywords:

"v4linux api filetype:pdf"

good luck! :D


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Tue Apr 28, 2009 12:00 pm 
Offline

Joined: Wed Apr 01, 2009 7:45 am
Posts: 20
Location: INDIA
what is the resolution of images you are getting from above code. because from uvccapture am getting 320*240( on my at91 board ), 640*480( on my desktop).
i did't understand what is the difference between desktop and at91. ( h/w is surely different but kernel am using is same 2.6.27)

i will try above code . thank you


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Wed Apr 29, 2009 5:50 pm 
Offline

Joined: Sat Jun 21, 2008 8:13 pm
Posts: 7
It's 640 X 480 , both monochrome and colour fully supported .
The code has a built in feature to show what resolution modes are supported by your camera , so use that to know what can do with your camera.
For more information try the author's web page. It's full of explanations and nice examples. :D


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Thu May 07, 2009 10:41 am 
Offline

Joined: Wed Apr 01, 2009 7:45 am
Posts: 20
Location: INDIA
can you send me the dmesg output .
because i figured the problem for low resolution.
from datasheet at91sam9260 has usb2.0 full/low host support.
but when i plug-in usb2.0high-speed webcam it is enumerated as full speed device and thus some resolutions are not availabel( higher resolutions are not available in full speed mode of usb).

i am wonder how you are able to get good amount of resolution on at91sam9260.
so please tell me when you plugged in is usb web cam enumerated as high or full speed device.

for high speed device you need a ehci-hdc module in kernel.

please give reply


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Thu May 07, 2009 8:16 pm 
Offline

Joined: Thu May 07, 2009 8:09 pm
Posts: 1
hi am student studying in iit ,i am trying this code for at91sam9263,i am able to compile this code.But while executing some errors are coming so pls try to solve this prob because i need to submit my project to college its running out of date so pls help me... the error msg i had given below

root@:/media/sda1/binfile# ./camm -q60 -x680 -y480 -t10 -w -v
./camm: invalid option -- 6
error: unknown option
Usage: cam [OPTION]...
without any options an image is written to stdout using current device settings

Options:
-h|--help print this help
-V|--version print program version number
-v|--verbose verbose program execution
-q|--quiet quiet program execution
-i|--info-only query capabilities of video device and exit
-s|--set-only set device parameters and exit
-f|--file|-o|--out-file=FILE write outpu
-d|--device=DEVICE specify video4linux DEVICE
-S|--size=WIDTHxHEIGHT set image WIDTH and HEIGHT
-S|--size=KEYWORD set image size described by KEYWORD
(--size=help for list)
-M|--max-size set maximum supported image size (obsolete)
-I|--min-size set minimum supported image size (obsolete)
-b|--brightness=BRIGHTNESS set BRIGHTNESS
-H|--hue=HUE set HUE
-c|--colour=COLOUR set COLOUR
-C|--contrast=CONTRAST set CONTRAST
-w|--whiteness=WHITENESS set WHITENESS (monochrome only)
-p|--palette=PALETTE set captur
(--palette=help for list)
-D|--depth=DEPTH set capture image DEPTH
-n|--channel=NUMBER set source channel NUMBER
-a|--auto-bright use vgrabber's automatic RGB brightness adjust
-t|--max-tries=NUMBER maximum NUMBER of tries for RGB brightness adjust
-R|--rgb-map=MAP mapping of red, green, and blue values
MAP = RGB | RBG | GRB | GBR | BGR | BRG
-g|--swap-gb swap green and blue bytes in output (obsolete)
-r|--swap-rb swap red and blue bytes in output (obsolete)
-l|--ignore-lsb ignore LSB in RGB555 mode
-m|--ignore-msb ignore MSB in RGB555 mode
-W|--write-raw write raw v4l output instead of PPM
-Y|--lum-only write a greyscale image using only Y value
(YUV palettes only)

Defaults:
write output to "./camm"
use v4l device "/dev/video0" for input
ignore most significant bit (MSB) when using RGB555 palette
maximum number of tries for brightness adjustment is 100
root@:/media/sda1/binfile#
root@:/media/sda1/binfile#
root@:/media/sda1/binfile# camm

root@:/media/sda1/binfile# ./camm -q60 -x680 -y480 -t10 -w -v
./camm: invalid option -- 6
error: unknown option
Usage: cam [OPTION]...
without any options an image is written to stdout using current device settings

Options:
-h|--help print this help
-V|--version print program version number
-v|--verbose verbose program execution
-q|--quiet quiet program execution
-i|--info-only query capabilities of video device and exit
-s|--set-only set device parameters and exit
-f|--file|-o|--out-file=FILE write output to FILE (- for stdout)
-d|--device=DEVICE specify video4linu
-S|--size=WIDTHxHEIGHT set image WIDTH and HEIGHT
-S|--size=KEYWORD set image size described by KEYWORD
(--size=help for list)
-M|--max-size set maximum supported image size (obsolete)
-I|--min-size set minimum supported image size (obsolete)
-b|--brightness=BRIGHTNESS set BRIGHTNESS
-H|--hue=HUE set HUE
-c|--colour=COLOUR set COLOUR
-C|--contrast=CONTRAST set CONTRAST
-w|--whiteness=WHITENESS set WHITENESS (monochrome only)
-p|--palette=PALETTE set capture image PALETTE
(--palette=help for list)
-D|--depth=DEPTH set capture image DEPTH
-n|--channel=NUMBER set source channel NUMBER
-a|--auto-bright use vgrabber's automatic RGB brightness adjust
-t|--max-tries=NUMBER maximum NUMBER of tries for RGB brightness adjust
-R|--rgb-map=MAP mapping of red, green, and blue values
MAP = RGB | RBG | GRB | GBR | BGR | BRG
-g|--swap-gb swap green and blue bytes in output (obsolete)
-r|--swap-rb swap red and blue bytes in output (obsolete)
-l|--ignore-lsb ignore LSB in RGB555 mode
-m|--ignore-msb ignore MSB i
-W|--write-raw write raw v4l output instead of PPM
-Y|--lum-only write a greyscale image using only Y value
(YUV palettes only)

Defaults:
write output to "./camm"
use v4l device "/dev/video0" for input
ignore most significant bit (MSB) when using RGB555 palette
maximum number of tries for brightness adjustment is 100


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Tue Apr 12, 2011 5:00 pm 
Offline

Joined: Wed Jul 21, 2010 11:35 am
Posts: 6
Hello,

just read what help says: "-q|--quiet quiet program execution". Parameter -q means quiet operation, not quality setting.


Top
 Profile  
 
 Post subject: Re: VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD
PostPosted: Sat Jun 11, 2011 7:38 am 
Offline

Joined: Sat Jun 21, 2008 8:13 pm
Posts: 7
Here's my finished contraption

http://www.youtube.com/watch?v=_4KwmhHec2Q


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: