[PLUG] program for taking a image from webcam
Suraj Swami
suraj.g.swami at gmail.com
Mon Apr 5 02:14:16 IST 2010
Hi,
I am trying to write a code to take a snap from the webcam and store it in .
But I am not able to do the basic reading of images. I get all zero value.
#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 <linux/types.h>
#include <linux/videodev.h>
#define FILE "/dev/video0"
int main(void)
{
int fd = open(FILE, O_RDONLY), f;
struct video_capability cap;
struct video_window win;
struct video_picture vpic;
unsigned char *buffer, *src;
int bpp = 24, r, g, b;
unsigned int i, src_depth;
if (fd < 0) {
perror(FILE);
exit(1);
}
if (ioctl(fd, VIDIOCGCAP, &cap) < 0) {
perror("VIDIOGCAP");
fprintf(stderr, "(" FILE " not a video4linux device?)\n");
close(fd);
exit(1);
}
if (ioctl(fd, VIDIOCGWIN, &win) < 0) {
perror("VIDIOCGWIN");
close(fd);
exit(1);
}
if (ioctl(fd, VIDIOCGPICT, &vpic) < 0) {
perror("VIDIOCGPICT");
close(fd);
exit(1);
}
// Set depth and palette ------------------------------------------------
this could be a major source of error. I get a error msg here. and if I
tried putting palette = 8 and depth = 16 it will work but I get all zero
values in the image.
vpic.depth=24;
vpic.palette=VIDEO_PALETTE_RGB24;
if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) {
fprintf(stderr, "Unable to find a supported capture format.\n");
return -1;
}
buffer = malloc(win.width * win.height * bpp);
if (!buffer) {
fprintf(stderr, "Out of memory.\n");
exit(1);
}
read(fd, buffer, win.width * win.height * bpp);
for (i = 0; i < win.width * win.height; i++) {
printf("\t %d,%d,%d",*src++,*src++,*src++);
}
close(fd);
}
I even get this code from net to get the present configuration and test
different pallete and I get this output.
(http://www.raphnet.net/programmation/v4l_tools/)
root at robot-laptop:~/webcam/v4l_tools-0.1/v4l_dump# ./v4l_dump
Using device /dev/video0
struct video_capability
{
name='Laptop Integrated Webcam'
channels=1
audios=0
maxwidth=1600
maxheight=1200
minwidth=48
minheight=32
}
VIDIOCGCHAN: Invalid argument
struct video_picture
{
brightness=29491
hue=0
colour=41942
contrast=36408
whiteness=21845
depth=0
palette=0
}
root at robot-laptop:~/webcam/v4l_tools-0.1/v4l_probe_palettes#
./v4l_probe_palettes
Using device /dev/video0
Supported palettes:
VIDEO_PALETTE_GREY: NO
VIDEO_PALETTE_HI240: NO
VIDEO_PALETTE_RGB565: NO
VIDEO_PALETTE_RGB24: NO
VIDEO_PALETTE_RGB32: NO
VIDEO_PALETTE_RGB555: NO
VIDEO_PALETTE_YUV422: MISMATCH. NO
VIDEO_PALETTE_YUV411: NO
VIDEO_PALETTE_RAW: NO
VIDEO_PALETTE_YUV422P: NO
VIDEO_PALETTE_YUV411P: NO
VIDEO_PALETTE_YUV420P: NO
I even get this code from net to test different pallete and I get this
output.
How do I fix this problem.
Thank you.
Regards,
Suraj Swami
More information about the Plug-mail
mailing list