Results 1 to 3 of 3
Hi everyone,
I am using fedora 14 64bit os(kernel 2.6.35). I want to capture image from web cam using v4l2 .I tried as
Code:
struct v4l2_capability cap;
int fd = ...
- 06-21-2011 #1Just Joined!
- Join Date
- Jun 2011
- Posts
- 3
capture and save image from webcam using v4l2
Hi everyone,
I am using fedora 14 64bit os(kernel 2.6.35). I want to capture image from web cam using v4l2 .I tried as
in process_buffer, i suppose to save the image.But when i am trying to save the color of image is not proper. I think the image datas are in 16bit per pixel.Code:struct v4l2_capability cap; int fd = open(dev_name,O_RDWR); int err = ioctl(fd,VIDIOC_QUERYCAP , &cap); struct v4l2_format format; format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; format.fmt.pix.width = 640; format.fmt.pix.height = 480; format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; err = ioctl(fd, VIDIOC_S_FMT, &format); struct v4l2_requestbuffers req; void **mem; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.count = 4; req.memory = V4L2_MEMORY_MMAP; err = ioctl(fd,VIDIOC_REQBUFS,&req); mem =(void **) malloc(req.count*(sizeof(*mem))); struct v4l2_buffer buffer; unsigned int i; for(i = 0;i < req.count;i++) { buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buffer.memory = V4L2_MEMORY_MMAP; buffer.index = i; err = ioctl(fd,VIDIOC_QUERYBUF,&buffer); mem[i] = mmap(0,buffer.length,PROT_READ|PROT_WRITE,MAP_SHARED,fd,buffer.m.offset); } int type = V4L2_BUF_TYPE_VIDEO_CAPTURE; for(i = 0 ; i < req.count ; i++) { buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buffer.memory = V4L2_MEMORY_MMAP; buffer.index = i; err = ioctl(fd,VIDIOC_QBUF,&buffer); } err= ioctl(fd,VIDIOC_STREAMON,&type); buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buffer.memory = V4L2_MEMORY_MMAP; err=ioctl(fd,VIDIOC_DQBUF,&buffer); process_buffer(mem[buffer.index],buffer);
Can any one tell how to save it ?
thanks
- 06-21-2011 #2Just Joined!
- Join Date
- Mar 2011
- Location
- NH
- Posts
- 14
RE: capture and save image from webcam using v4l2
If you attach a dump of the buffer, it would be a lot easier for someone to help. If you can write it as a TIFF so much the better.
OTOH, if you are just trying to capture an image from a Web cam, why not just access via HTTP? Or is it actually a USB cam?
- 06-22-2011 #3Just Joined!
- Join Date
- Jun 2011
- Posts
- 3
Yes it is a usb logitech web cam.
How i will access via HTTP ?
I tried to run v4lgrab.c (inside linux kernel source -: linux-2.6.35/Documentation/video4linux).But it is showing "/dev/video0 is not a video4linux device".


Reply With Quote