对比度和亮度(二)
作者:
小小蒟蒻
,
2021-11-14 06:19:42
,
所有人可见
,
阅读 295
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
int main()
{
string path = "test.jpg";
cv::Mat img = cv::imread(path, cv::IMREAD_COLOR);
if (img.empty())
{
cout << "failed to read image" << endl;
return -1;
}
double alpha = 0.5, beta = 0; // alpha < 1
cv::Mat res1;
img.convertTo(res1, -1, alpha, beta);
if (res1.empty())
{
cout << "failed to convert image" << endl;
return -1;
}
cv::imshow("src", img);
cv::imshow("alpha < 1", res1);
alpha = 1.2, beta = 0; // alpha > 1
cv::Mat res2;
img.convertTo(res2, -1, alpha, beta);
if (res2.empty())
{
cout << "failed to convert image" << endl;
return -1;
}
cv::imshow("alpha > 1", res2);
cv::waitKey(0);
return 0;
}