OpenCV C++ 改变图片亮度、对比度
一、改变图片视频亮度
1. 图片
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main() {
Mat img = imread("C:/Users/12271/Desktop/test/eren.jpg");
if (img.empty() == 1) {
cout << "cannot load the image" << endl;
return -1;
}
Mat img_brighness_high100, img_brighness_low100;
img.convertTo(img_brighness_high100, -1, 1, 100);
img.convertTo(img_brighness_low100, -1, 1, -100);
string high_img = "brighness high 100", low_img = "brighness low 100", original = "original";
namedWindow(high_img);
namedWindow(low_img);
namedWindow(original);
imshow(high_img, img_brighness_high100);
imshow(low_img, img_brighness_low100);
imshow(original, img);
waitKey(0);
destroyAllWindows();
}
2. 视频
更改视频亮度时要将新建数组放在while循环内,每帧都要创建一个新数组用来存放更改亮度后的图片。
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std