Opencv圖片明暗處理ios
#include <iostream> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; //圖片明暗處理 cv::Mat shadingTreatment(cv::Mat imgParam); int main() { double alpha; //對比度 int beta; //亮度 //Mat image = imread("F:\\OpencvProject\\CamerasAndSurveillance201910\\x64\\Debug\\face_data\\20191025143712025.jpg"); Mat image = imread("D:\\images\\特朗普\\0.jpg"); if (image.empty()) { return 0; } cv::Mat new_image = shadingTreatment(image); /// 目標圖像空間預分配 /// 顯示圖像 imshow("原圖像", image); imshow("新圖像", new_image); /// 等待鍵盤事件 waitKey(0); return 0; } //圖片明暗處理 cv::Mat shadingTreatment(cv::Mat imgParam) { Mat new_image = Mat::zeros(imgParam.size(), imgParam.type()); /// 輸入初始化值 //cout << "請輸入對比度1-3: "; //cin >> alpha; //cout << "請輸入亮度1-100: "; //cin >> beta; double alpha = 1.2; int beta = 50; /// 執行變換 new_image(i,j) = alpha * image(i,j) + beta for (int y = 0; y < imgParam.rows; y++) { for (int x = 0; x < imgParam.cols; x++) { for (int c = 0; c < 3; c++) { new_image.at<Vec3b>(y, x)[c] = saturate_cast<uchar>(alpha * (imgParam.at<Vec3b>(y, x)[c]) + beta); } } } return new_image; }