Developing a camera program in Linux mainly uses
In video4linux, QT is used to implement the interface and frame is ready for use.
Buffer to directly write the screen, but the effect is not very good, and then we use qt to do it. In this way, the effect is quite good, and the frame rate can also be up to 30fps; use v4l for programming
The most important thing to improve the frame rate is to use memory ing. In fact, using QT and Frame
Memory ing must be used for buffer, so that a high frame rate can be achieved. However, pay attention to resource utilization. munmap must be used after MMAP. For Frame
Buffer is a very interesting thing, especially the driver design.
1. Open device:
Video_dev = open ("/dev/video0", o_rdwr ));
2. Get the information of the Video device
Struct video_capability video_cap;
Memset (& video_cap, 0, sizeof (video_cap ));
If (IOCTL (video_dev, vidiocgcap, & video_cap) =-1)
{
Perror ("cann' t get the information of the Video device ");
Close (video_dev );
Exit (1 );
}
3. Get the information of the channels
Struct video_channel video_chan;
Memset (& video_chan, 0, sizeof (video_chan ));
For (Channel = 0; Channel <video_cap.channels; Channel ++)
{
Video_chan.channel = channel;
If (IOCTL (video_dev, vidiocgchan, & video_chan) =-1)
{
Perror ("cann' t get the information of the channels ");
Close (video_dev );
Exit (3 );
}
If (video_chan.type = video_type_ TV)
{
# Ifdef debug
Printf ("No. % d channel is % s, type is TV! /N ", channel, video_chan.name );
# Endif
}
If (video_chan.type = video_type_camera)
{
If (IOCTL (video_dev, vidiocschan, & video_chan) =-1)
{
Perror ("cann' t set the camera channel! ");
Close (video_dev );
Exit (4 );
}
}
}
4. Get the capture attributes
Struct video_picture video_pic;
Memset (& video_pic, 0, sizeof (video_pic ));
If (IOCTL (video_dev, vidiocgpict, & video_pic) =-1)
{
Perror ("cann' t get the picture attributes of the device! ");
Close (video_dev );
Exit (5 );
}
5. Set capture attributes
Video_pic.palette = video_palette _ *****; // different camera has different palette
Video_pic.brightness = 65535;
Video_pic.colour = 0;
If (IOCTL (video_dev, vidiocspict, & video_pic) =-1)
{
Perror ("cann' t set the picture attributs! ");
Close (video_dev );
Exit (6 );
}
6. MMAP the device
Struct video_mbuf mbuf;
Unsigned char * frames;
Memset (& mbuf, 0, sizeof (mbuf ));
If (IOCTL (video_dev, vidiocgmbuf, & mbuf) =-1)
{
Perror ("cann' t get the buffer information of the Video device! ");
Close (video_dev );
Exit (7 );
}
Frames = (unsigned char *): MMAP (0, mbuf. Size, prot_read | prot_write, map_shared, video_dev, 0 );
If (! Frames | frames = (unsigned char *) (long) (-1 ))
{
Perror ("the device cann' t be memory mapped! ");
Close (video_dev );
Exit (8 );
}
7. Capture
If (IOCTL (video_dev, vidiocmcapture, & MMAP) =-1)
{
Perror ("capture failed! ");
Close (video_dev );
Exit (9 );
}
Else
{
// Display or save the picture file
}