如何使用 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);
}

輸出

更新日期:2021-3-10

363 檢視次數

開啟你的 職業生涯

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.