关于opencv更改摄像头参数(帧率,分辨率,曝光度……)的
⼏个问题
1,适⽤于VideoCapture打开的摄像头
VideoCapture capture(0); 设置摄像头参数不要随意修改
capture.set(CV_CAP_PROP_FRAME_WIDTH, 1080);//宽度
capture.set(CV_CAP_PROP_FRAME_HEIGHT, 960);//⾼度
capture.set(CV_CAP_PROP_FPS, 30);//帧率帧/秒
capture.set(CV_CAP_PROP_BRIGHTNESS, 1);//亮度
capture.set(CV_CAP_PROP_CONTRAST,40);//对⽐度 40
capture.set(CV_CAP_PROP_SATURATION, 50);//饱和度 50
capture.set(CV_CAP_PROP_HUE, 50);//⾊调 50
capture.set(CV_CAP_PROP_EXPOSURE, 50);//曝光 50 获取摄像头参数
得到摄像头的参数
<(CV_CAP_PROP_FRAME_WIDTH);
<(CV_CAP_PROP_FRAME_HEIGHT);
<(CV_CAP_PROP_FPS);
<(CV_CAP_PROP_BRIGHTNESS);
<(CV_CAP_PROP_CONTRAST);
<(CV_CAP_PROP_SATURATION);
<(CV_CAP_PROP_HUE);
<(CV_CAP_PROP_EXPOSURE); 获取视频参数:
<(CV_CAP_PROP_FRAME_COUNT);//视频帧数
2,不做开发,只是单纯的更改
补,现在突然想起来我的⼀个学长告诉我的,利⽤这个软件调节摄像头的曝光度,可以改变帧率,且摄像头会记住曝光度的设置(其他特性就没有这个特点)
3,修改opencv的⽂件,不过效果可能和第⼀个差不多
⼤概是在opencv的这个位置,⼀下,modules/highgui/src/cap_v4l.cpp,⾥⾯有关于参数的设置,位置⽐较靠前,可以搜索,也可以直接到
4,v4l2
mmap格式怎么打开下⾯是我到的⼀篇参考,可以突破帧率的限制,当然前提是摄像头⽀持
⽬前只适⽤于Linux系统,本⼈试验过,120帧的摄像头在只打开摄像头时可以达到100帧左右,设置的图⽚分辨率越⼩,能达到的帧率越⾼
#include <unistd.h>
#include <error.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <pthread.h>
#include <linux/videodev2.h>
#include <sys/mman.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <math.h>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
using namespace cv;
#define CLEAR(x) memset(&(x), 0, sizeof(x))
#define IMAGEWIDTH 3264
#define IMAGEHEIGHT 2448
#define WINDOW_NAME1 "【原始图】" //为窗⼝标题定义的宏
#define WINDOW_NAME2 "【图像轮廓】" //为窗⼝标题定义的宏
Mat g_srcImage; Mat g_grayImage;
int g_nThresh = 90;
int g_nMaxThresh = 255;
RNG g_rng(12345);
Mat g_cannyMat_output;
vector<vector<Point> > g_vContours;
vector<Vec4i> g_vHierarchy;
Point point1[100000];
Point point2[100000];
Point point3[100000];
int ii,iii;
int flag2 = 0;//避障⽤
float number = 0;
int fps=0;
class V4L2Capture {
public:
V4L2Capture(char *devName, int width, int height);
virtual ~V4L2Capture();
int openDevice();
int closeDevice();
int closeDevice();
int initDevice();
int startCapture();
int stopCapture();
int freeBuffers();
int getFrame(void **,size_t *);
int backFrame();
static void test();
private:
int initBuffers();
struct cam_buffer
{
void* start;
unsigned int length;
};
char *devName;
int capW;
int capH;
int fd_cam;
cam_buffer *buffers;
unsigned int n_buffers;
int frameIndex;
};
V4L2Capture::V4L2Capture(char *devName, int width, int height) { // TODO Auto-generated constructor stub
this->devName = devName;
this->fd_cam = -1;
this->buffers = NULL;
this->n_buffers = 0;
this->frameIndex = -1;
this->capW=width;
this->capH=height;
}
V4L2Capture::~V4L2Capture() {
// TODO Auto-generated destructor stub
}
int V4L2Capture::openDevice() {
/*设备的打开*/
printf("video dev : %s\n", devName);
fd_cam = open(devName, O_RDWR);
if (fd_cam < 0) {
perror("Can't open video device");
}
return 0;
}
int V4L2Capture::closeDevice() {
if (fd_cam > 0) {
int ret = 0;
if ((ret = close(fd_cam)) < 0) {
perror("Can't close video device");
}
return 0;
} else {
return -1;
}
}
int V4L2Capture::initDevice() {
int ret;
struct v4l2_capability cam_cap; //显⽰设备信息
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论