V4L2 image grabbing

Find the source code here:

https://bitbucket.org/nandan_dubey/v4l2-grabbing/src

 

static int xioctl(int fd, int request, void *arg)

as name suggest this is for I/O control sending special request to the file.

You need to set the format image size (width x height) cropping parameter if need be

Then there are multiple ways to access the image data you can use mmap which is used here. This is fastest and most used. This maps the driver kernel memory space to user so that you can directly read from there. The image captured data.

For V4L2 capturing there are two I/O controls for continuous capturing:

VIDIOC_QBUF and VIDIOC_DQBUF

You can make your /dev/video0 [or any number] file non -blocking but then you have to do select(fd+1, &fds, NULL, NULL, &tv); for next I/O as in async mode you don’t know when your file is ready for next I/O. It may be possible that previous I/O is still in progress.

You can try with non-blocking read by changing below:

fd = open(“/dev/video0”, O_RDWR);

 

VIDIOC_STREAMON this ioctl sets the required parameters in the camera/sensor so that sensor starts streaming. Basically for any sensor you need to set some register values before it starts working all these settings will be done when you send this ioctl to the driver.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s