Opencv4调试摄像头参数示例

Posted yamboo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Opencv4调试摄像头参数示例相关的知识,希望对你有一定的参考价值。

#pragma execution_character_set("utf-8")
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>

int main()
{
    cv::VideoCapture capDevice(0);
    capDevice.open(0);
    //设置摄像头采集图像分辨率
    capDevice.set(cv::CAP_PROP_FRAME_WIDTH, 1024.0);
    capDevice.set(cv::CAP_PROP_FRAME_HEIGHT, 960.0);

    capDevice.set(cv::CAP_PROP_FRAME_WIDTH, 1080);//宽度 
    capDevice.set(cv::CAP_PROP_FRAME_HEIGHT, 960);//高度
    //capDevice.set(cv::CAP_PROP_FPS, 30);//帧率 帧/秒
    capDevice.set(cv::CAP_PROP_BRIGHTNESS, 1);//亮度 1
    capDevice.set(cv::CAP_PROP_CONTRAST, 60);//对比度 40
    capDevice.set(cv::CAP_PROP_SATURATION, 64);//饱和度 50
    capDevice.set(cv::CAP_PROP_HUE, 0);//色调
    capDevice.set(cv::CAP_PROP_EXPOSURE, -7);//曝光 50
    cv::Mat srcImage;

    //宽度 
    double width = capDevice.get(cv::CAP_PROP_FRAME_WIDTH);
    //高度
    double height = capDevice.get(cv::CAP_PROP_FRAME_HEIGHT);
    //帧率 帧/秒
    //int fps = capDevice.get(cv::CAP_PROP_FPS);
    //亮度
    double bright = capDevice.get(cv::CAP_PROP_BRIGHTNESS);
    //对比度
    double contrast = capDevice.get(cv::CAP_PROP_CONTRAST);
    //饱和度
    double saturation = capDevice.get(cv::CAP_PROP_SATURATION);
    //色调
    double hue = capDevice.get(cv::CAP_PROP_HUE);
    //曝光时长
    double exposure = capDevice.get(cv::CAP_PROP_EXPOSURE);

    //设置绘制文本的相关参数
    char text[255] = "";
    int font_face = cv::FONT_HERSHEY_COMPLEX;
    double font_scale = 1;
    int thickness = 1;

    while (true) {
        if (capDevice.isOpened())
        {
            capDevice >> srcImage;
        }

        sprintf(text, "width:%0.1f height:%0.1f exposure:%0.1f", width, height, exposure);
        cv::putText(srcImage, text, cv::Point(20, 30), font_face, font_scale, cv::Scalar(0, 255, 255), thickness, 8, 0);

        sprintf(text, "bright:%0.1f contrast:%0.1f saturation:%0.1f hue:%0.1f", bright, contrast, saturation, hue);
        cv::putText(srcImage, text, cv::Point(20, 90), font_face, font_scale, cv::Scalar(0, 255, 255), thickness, 8, 0);

        imshow("image", srcImage);
        cv::waitKey(30);
    }
}

 

以上是关于Opencv4调试摄像头参数示例的主要内容,如果未能解决你的问题,请参考以下文章

opencv系列03OpenCV4.X视频获取与显示

Processing 中使用OpenCV4处理摄像头画面

Processing 中使用OpenCV4处理摄像头画面

Opencv4日常学习任务和日历

方便调试使用的代码片段

Processing 中使用OpenCV4处理摄像头画面