#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/videodev.h>
#include <string.h>
#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;
}
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |