【OpenCV 学习之路】(7)滑动条的使用之二

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/u011897411/article/details/88381941

先看效果图:
对摄像头采集的图片处理

Talk is cheap,show you the code.

#include<opencv2\core\core.hpp>  
#include<opencv2\highgui\highgui.hpp>  
#include<opencv2\imgproc\imgproc.hpp>  
using namespace cv;

void on_Contrast(int, void*);

VideoCapture cap(0);
Mat frame;
int contrast = 100, bright = 50;//0-3.0,0-2.0 

int main()
{
    cap >> frame;
    namedWindow("原图", 1);
    namedWindow("效果图", 1);
    while (1)
    {
        cap >> frame;
        imshow("原图", frame);
        createTrackbar("对比度", "效果图", &contrast, 300, on_Contrast);
        createTrackbar("明亮度", "效果图", &bright, 200, on_Contrast);
        on_Contrast(contrast, 0);
        on_Contrast(bright, 0);
        waitKey(1);
    }
    waitKey(0);
    return 0;
}

void on_Contrast(int, void*)
{
    for (int y = 0; y < frame.rows; y++)
    {
        for (int x = 0; x < frame.cols; x++)
        {
            for (int c = 0; c < 3; c++)
            {
                frame.at<Vec3b>(y, x)[c] = saturate_cast<uchar>(frame.at<Vec3b>(y, x)[c] * contrast*0.01 + bright);
            }
        }
    }
    imshow("效果图", frame);
}

学会了对图片(【OpenCV 学习之路】(6)滑动条的使用之一)进行对比度,明亮度操作之后,再来看对视频的操作会发现很简单。

在这个过程中遇到的问题不大,但要注意的是:

  1. 循环里面一定要加上延时,不然运行不了,不知道为什么。
  2. 画面有延迟,应该是遍历像素的方法问题。

猜你喜欢

转载自blog.csdn.net/u011897411/article/details/88381941