资源简介
Linux环境下使用V4L2+opencv以MJPEG格式读取USB摄像头并实时显示的源代码
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
uchar *buffer;
#define IMAGEWIDTH 640
#define IMAGEHEIGHT 480
#define TRUE 1
#define FALSE 0
#define FILE_VIDEO1 “/dev/video1“
static int fd;
struct v4l2_streamparm setfps;
struct v4l2_capability cap;
struct v4l2_fmtdesc fmtdesc;
struct v4l2_format fmtfmtack;
struct v4l2_requestbuffers req;
struct v4l2_buffer buf;
enum v4l2_buf_type type;
int init_v4l2(void);
int v4l2_grab(void);
int main()
{
printf(“first~~\n“);
if(init_v4l2() == FALSE){
printf(“Init fail~~\n“);
exit(1);
}
printf(“second~~\n“);
if(v4l2_grab() == FALSE){
printf(“grab fail~~\n“);
exit(2);
}
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
printf(“third~~\n“);
cvNamedWindow(“one“CV_WINDOW_AUTOSIZE);
IplImage* img;
CvMat cvmat;
int i = 100;
double t;
while(1){
t = (double)cvGetTickCount();
ioctl(fdVIDIOC_DQBUF&buf);
buf.index = 0;
cvmat = cvMat(IMAGEHEIGHTIMAGEWIDTHCV_8UC3(void*)buffer);//CV_8UC3
//t = (double)cvGetTickCount();
img = cvDecodeImage(&cvmat1);
//t=(double)cvGetTickCount()-t;
//printf(“used time is %gms\n“(t/(cvGetTickFrequency()*1000)));
if(!img) printf(“No img\n“);
cvShowImage(“one“img);
cvReleaseImage(&img);
ioctl(fdVIDIOC_QBUF&buf);
if((cvWaitKey(1)&255) == 27) exit(0);
t=(double)cvGetTickCount()-t;
printf(“used time is %gms\n“(t/(cvGetTickFrequency()*1000)));
}
ioctl(fdVIDIOC_STREAMOFF&type);
return 0;
}
int init_v4l2(void){
if ((fd = open(FILE_VIDEO1 O_RDWR)) == -1){
printf(“Opening video device error\n“);
return FALSE;
}
if (ioctl(fd VIDIOC_QUERYCAP &cap) == -1){
printf(“unable Querying Capabilities\n“);
return FALSE;
}
else
/*
{
printf( “Driver Caps:\n“
“ Driver: \“%s\“\n“
“ Card: \“%s\“\n“
“ Bus: \“%s\“\n“
“ Version: %d\n“
“ Capabilities: %x\n“
cap.driver
cap.card
cap.bus_info
cap.version
cap.capabilities);
}
if((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == V4L2_CAP_VIDEO_CAPTURE){
printf(“Camera device %s: support capture\n“FILE_VIDEO1);
}
if((cap.capabilities & V4L2_CAP_STREAM
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 248 2015-08-12 16:19 singleCamD\singleCamD.pro
文件 18135 2015-08-12 20:59 singleCamD\singleCamD.pro.user
文件 6306 2015-08-12 20:46 singleCamD\main.cpp
目录 0 2015-08-12 20:59 singleCamD
----------- --------- ---------- ----- ----
24689 4
相关资源
- MAX9286的V4L2测试代码
- webcam_v4l2_x264
- 嵌入式平台ARm9使用V4L2格式摄像头抓帧
- linux下基于QT和v4l2驱动的USB摄像头视频
- 智能家居的项目用的 V4L2
- v4l2采集视频并保存和lcd显示
- v4l2 QT MJPEG格式 视频采集+屏幕显示+图
- 使用Linux的V4L2读取摄像头数据+Opencv图
- v4l2 qt实时显示摄像头数据未使用ope
- V4L2视频采集与h264编码
- linux下v4l2实现图片采集
- 基于QT的V4L2摄像头视频采集并显示
- tiny4412 + qtopia + v4l2 + usb camera
- Linux Media Subsystem Documentation
- 冒死上传公司车载设备源码 支持gp
- V4L2+FFMPEG+live555实现流媒体服务端
- LINUX下采集视频数据并编码为H264项目
- Linux 下V4l2摄像头采集图片,实现yuy
- linux v4l2视频采集教程
- TI OMAP3 ISP驱动整体框架、流程整理分
- 基于V4l2的uvc摄像头视频录像代码avi
- linux下v4l2视频采集源代码
- Linux 下 v4l2 和 Qt 连接usb摄像头
- UVC驱动抓图测试程序--基于V4L2
评论
共有 条评论