- 加减乘除
- 利用加法调整图像亮度
- 调整图像亮度与对比度
- 加减乘除
输入图像的大小与类型必须一致
处理越界
#include <opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
Mat src1 = imread("D:/HUANGHAI_WORK/tools/opencv4/opencv/sources/samples/data/WindowsLogo.jpg", IMREAD_UNCHANGED);
Mat src2 = imread("D:/HUANGHAI_WORK/tools/opencv4/opencv/sources/samples/data/LinuxLogo.jpg", IMREAD_UNCHANGED);
namedWindow("input1", WINDOW_NORMAL);
imshow("input1", src1);
imshow("input2", src2);
//加
Mat dst1;
add(src1, src2, dst1);
imshow("加", dst1);
//减
Mat dst2;
subtract(src1, src2, dst2);
imshow("减", dst2);
//乘
Mat dst3;
multiply(src1, src2, dst3);
imshow("乘", dst3);
//除
Mat dst4;
divide(src1, src2, dst4);
imshow("除", dst4);
waitKey(0);
destroyAllWindows();
return 0;
}
image.png
- 亮度和对比度
//亮度
Mat t1 = imread("D:/HUANGHAI_WORK/tools/opencv4/opencv/sources/samples/data/messi5.jpg");
imshow("t1", t1);
Mat black = Mat::zeros(t1.size(), t1.type());
black = Scalar(127, 127, 127);
Mat dst1;
add(t1, black, dst1);
imshow("dst1", dst1);
//亮度和对比度
Mat dst2;
addWeighted(t1, 1.2, black, 0.5, 0.0, dst2);
imshow("dst2", dst2);
image.png
网友评论