如何使用 C++ 在 OpenCV 中降低图像的亮度?
降低亮度的做法与提高亮度非常相似。唯一不同的是从图像中减去“标量 (B, G, R)”。这里,我们减去标量值来降低亮度。
以下是使用 OpenCV 降低图像亮度的程序。
示例
#include<iostream> #include<opencv2/highgui/highgui.hpp> using namespace cv; using namespace std; int main() { Mat original; //Declaring a matrix to load the original image// Mat dimmer;//Declaring a matrix to load the image after changing the brightness// namedWindow("Original");//Declaring window to show the original image// namedWindow("Dimmer");//Declaring window to show the brighter image// original = imread("bright.jpg"); dimmer = original - Scalar(80, 80, 80);//subtracting integer value to change the brightness// imshow("Original", original);//showing original image// imshow("Dimmer", dimmer);//showing brighter image// waitKey(0);//wait for keystroke// return(0); }
输出
广告