概述
#include <opencv2/opencv.hpp>
cv::VideoCapture cap;
int fps = 30;
int hue = 50;//色调
int saturation = 50;//饱和度
int contrast = 50;//对比度
int brightness = 50;//亮度
int exposure = 50;//曝光
void on_FPS_trackbar(int ,void *)
{
cap.set(CV_CAP_PROP_FPS, 30);//帧数30
}
void on_HUE_trackbar(int ,void *)
{
cap.set(CV_CAP_PROP_HUE,hue * 0.01);
}
void on_SATURATION_trackbar(int ,void *)
{
cap.set(CV_CAP_PROP_SATURATION,saturation * 0.01);
}
void on_BRIGHTNESS_trackbar(int ,void *)
{
cap.set(CV_CAP_PROP_BRIGHTNESS,brightness * 0.01);
}
void on_CONTRAST_trackbar(int ,void *)
{
cap.set(CV_CAP_PROP_CONTRAST,contrast * 0.01);
}
void on_EXPOSURE_trackbar(int ,void *)
{
cap.set(CV_CAP_PROP_EXPOSURE,exposure * 0.01);
}
int main(int argc,char* argv[])
{
if(argc != 2){
printf("eg:cap 1n");
return -1;
}
int dev_number = atoi((const char*)argv[1]);
cap.open(dev_number);
if(!cap.isOpened())
{
printf("打开摄像头失败:number=%dn",dev_number);
}else {
printf("宽度width = %.2fn",cap.get(CV_CAP_PROP_FRAME_WIDTH));
printf("高度height = %.2fn",cap.get(CV_CAP_PROP_FRAME_HEIGHT));
printf("帧率fps = %.2fn",cap.get(CV_CAP_PROP_FPS));
printf("色调hue = %.2fn",cap.get(CV_CAP_PROP_HUE));
printf("饱和度saturation = %.2fn",cap.get(CV_CAP_PROP_SATURATION));
printf("对比度contrast = %.2fn",cap.get(CV_CAP_PROP_CONTRAST));
printf("亮度brightness = %.2fn",cap.get(CV_CAP_PROP_BRIGHTNESS));
printf("曝光exposure = %.2fn",cap.get(CV_CAP_PROP_EXPOSURE));
cap.set(CV_CAP_PROP_FPS, 30);//帧数30
cap.set(CV_CAP_PROP_HUE,hue * 0.01);
cap.set(CV_CAP_PROP_SATURATION,saturation * 0.01);
cap.set(CV_CAP_PROP_BRIGHTNESS,brightness * 0.01);
cap.set(CV_CAP_PROP_CONTRAST,contrast * 0.01);
cap.set(CV_CAP_PROP_EXPOSURE,exposure * 0.01);
}
cv::namedWindow("camera");
cv::createTrackbar("帧率","camera", &fps, 100, on_FPS_trackbar);
cv::createTrackbar("色调","camera", &hue, 100, on_HUE_trackbar);
cv::createTrackbar("饱和度","camera", &saturation, 100, on_SATURATION_trackbar);
cv::createTrackbar("对比度","camera", &contrast, 100, on_CONTRAST_trackbar);
cv::createTrackbar("亮度","camera", &brightness, 100, on_BRIGHTNESS_trackbar);
cv::createTrackbar("曝光","camera", &exposure, 100, on_EXPOSURE_trackbar);
cv::Mat srcImage;
while(1)
{
cap >> srcImage;
cv::imshow("camera",srcImage);
char c = cv::waitKey(1);
if(c == 27)
{
break;
}
}
cap.release();
return 0;
}
最后
以上就是甜甜小刺猬为你收集整理的使用opencv进行USB摄像头参数配置的全部内容,希望文章能够帮你解决使用opencv进行USB摄像头参数配置所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复