|
小弟初学V4L
照葫芦画瓢写了视频采集的代码
但是不知道如何调用显示模块
请高手帮忙指点一下,谢谢
[code:1]
#include "v4l.h"
#define COLS 320
#define ROWS 240
int main(int argc, char *argv[])
{
int cam;
cam = open("/dev/video0", O_RDWR); // 打开摄像头,返回文件描述符
if(cam < 0) {
printf("No Camera Connected!\n");
exit(-1);
}
struct video_capability cap;
if(-1 == ioctl(cam, VIDIOCGCAP, &cap)) { // 获取摄像头信息
perror("ioctl VIDIOCGCAP");
exit(-1);
}
printf("Device name -> %s\n", cap.name);
printf("Device type -> %d\n", cap.type);
printf("Channels -> %d\n", cap.channels);
printf("Maxwidth -> %d\n", cap.maxwidth);
printf("Maxheight -> %d\n", cap.maxheight);
printf("Minwidth -> %d\n", cap.minwidth);
printf("Minheight -> %d\n", cap.minheight);
printf("\n********************************\n");
struct video_picture pic;
if(-1 == ioctl(cam, VIDIOCGPICT, &pic) ) { // 读取图像属性
perror("ioctl VIDIOCSPICT");
exit(-1);
}
ioctl(cam, VIDIOCGPICT, &pic);
printf("Brightness -> %d\n", pic.brightness / 256);
printf("Colour -> %d\n", pic.colour / 256);
printf("Contrast -> %d\n", pic.contrast / 256);
printf("Whiteness -> %d\n", pic.whiteness / 256);
printf("Depth -> %d\n", pic.depth);
printf("Palette -> %d\n", pic.palette);
struct video_mmap mapbuf; //
mapbuf.width = COLS; // 图像宽度
mapbuf.height = ROWS; // 图像高度
mapbuf.format = VIDEO_PALETTE_RGB24;
struct video_mbuf vidbuf;
unsigned char *grab_data;
if(-1 == ioctl(cam, VIDIOCGMBUF, &vidbuf)) { // 设备缓存
perror("ioctl VIDIOCGMBUF");
exit(-1);
}
printf("vidbuf.size = %d\n", vidbuf.size);
if( (grab_data = (unsigned char *)mmap(0, vidbuf.size, PROT_READ | PROT_WRITE, MAP_SHARED, cam, 0)) < 0){
perror("v4l_mmap :"); // 将内存映射区段与设备缓存绑定,返回实际内存指针
exit(-1);
}
unsigned char *buf;
int frame = 0, i;
printf("\nvidbuf.frames: %d\n", vidbuf.frames);
if(ioctl(cam, VIDIOCMCAPTURE, &mapbuf) < 0) {
perror("VIDIOCMCAPTURE");
exit(-1);
}
while(1){
i = -1;
while(i < 0){
i = ioctl(cam, VIDIOCSYNC, &frame); // 检查视频采集是否完成
if(i < 0 && errno == EINTR) continue;
break;
}
buf = grab_data + vidbuf.offsets[frame];
mapbuf.frame = frame;
// 在此可以调用显示模块,不知如何写显示模块??
if(ioctl(cam, VIDIOCMCAPTURE, &mapbuf) < 0) {
perror("VIDIOCMCAPTURE");
exit(-1);
}
frame++;
if(frame >= vidbuf.frames) frame = 0;
}
close(cam);
free("/dev/video0");
return EXIT_SUCCESS;
}
[/code:1] |
|