#include #define Video "/dev/video0"
#define Audio "/dev/dsp"
#define DEF_WIDTH 320
#define DEF_HEIGHT 240
/************************************
*name : main
*
*
*
*
*
*
************************************/
int main(int argc,char*argv[])
{
unsigned char buf[(320*240)/8];
int fd,;
int num;
/*define the struct */
struct video_capability vid_cap; /*摄像头参数结构*/
/*get the device number and saved to fd*/
fd=open(Video,O_WRONLY);
if(fd==-1){
perror("Can't open the Video device!\n");
return 1;
}else printf("Open the video device success!\n fd = %d\n",fd);
/*through ioctl function to init the device struct*/
if(ioctl(fd,VIDIOCGCAP,&vid_cap)<0)
{
perror("VIDIOCGCAP");
return 1;
}
fprintf(stderr,"Video Capture Device Name : %s\n",vid_cap.name);
fprintf(stderr,"Video Capture Device type : %d\n",vid_cap.type);
fprintf(stderr,"Video Capture Device channels : %d\n",vid_cap.channels);
fprintf(stderr,"Video Capture Device audios : %d\n",vid_cap.audios);
fprintf(stderr,"Video Capture Device max_W : %d\n",vid_cap.maxwidth);
fprintf(stderr,"Video Capture Device max_H : %d\n",vid_cap.maxheight);
fprintf(stderr,"Video Capture Device min_W : %d\n",vid_cap.minwidth);
fprintf(stderr,"Video Capture Device min_H : %d\n",vid_cap.minheight);
这个程序是获取摄像头的属性,接下来的步骤是获取图像信息,读取、保存图像,
直接通过read读取,但是不成功
if(read(fd,buf,(240*320)/8)<0)
{
perror("Can't read the picture!\n");
return 1;
}
在上面的读取摄像头属性的时候 可以正常读出摄像头的属性,但是后面读不出图片,好像是不能直接这样用read读,
现在就是不知道还有那些特定的相关的“结构”参数需要设置,也可能是这个原因,大家帮忙看一下。
谢谢!!