UVC / V4L2 webcam / grab
I need to grab single frames from a UVC / V4L2 webcam with low latency and I need the frame
to be acquired ASAP _after_ another event has occurred. The code I am using is ~ that below
and the problem I have is that unless I grab one frame and discard it I find the frame I grab (the
image) sometimes contains things that could only occur _prior_ to the capture code being called.
In pseudo code my problem looks like this:
The problem is the data may contain output from condition (1) even if DELAY is long enough
to guarantee the image should only contain and image from condition (2). If I do something like:
the second grab returns the correct image regardless of what DELAY I use.
This may be a stupid problem and I am not too familiar with how V4L2 works but here goes:
What is the easiest way to use V4L2 to grab an individual frame from a UVC webcam and
ensure that the data in the frame relates to an image that occurred _after_ the grab was
requested? second part is, what is the fastest / simplest way to do this?
I don't even know if it is possible to ensure this because I suppose hardware limitations
may prevent a deterministic result.
Sorry for cryptic explanation, the detailed one would take a huge space to explain.
Simplest terms I am changing the lighting conditions then capturing the result, say this was
from red->blue lighting, some of my grabbed images contain red when it would be impossible
to do so unless the data I received was captured before I requested it.
// code snippet
// set up...
int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ret = ioctl (vd->fd, VIDIOC_STREAMON, &type);
// code to run at capture
memset (&vd->buf, 0, sizeof (struct v4l2_buffer));
vd->buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
vd->buf.memory = V4L2_MEMORY_MMAP;
ret = ioctl (vd->fd, VIDIOC_DQBUF, &vd->buf);
memcpy (vd->framebuffer, vd->mem[vd->buf.index],(size_t) vd->framesizeIn);
ret = ioctl (vd->fd, VIDIOC_QBUF, &vd->buf);
Share your memories online with anyone you want.
video4linux-list mailing list