mirror of
https://github.com/NanjingForestryUniversity/uppermachine-candy.git
synced 2025-11-08 14:24:15 +00:00
51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
#include "correct.h"
|
|
|
|
Correct::Correct()
|
|
{
|
|
is_corrected = false;
|
|
correction_ratio_r = 1;
|
|
correction_ratio_g = 1;
|
|
correction_ratio_b = 1;
|
|
}
|
|
|
|
void Correct::get_rgb(cv::Mat img)
|
|
{
|
|
int b_temp = 0;
|
|
int g_temp = 0;
|
|
int r_temp = 0;
|
|
for(int i=0; i<=img.rows; i++)
|
|
{
|
|
for(int j=0; j<=img.cols; j++)
|
|
{
|
|
b_temp += (int)img.at<cv::Vec3b>(i, j)[0];
|
|
g_temp += (int)img.at<cv::Vec3b>(i, j)[1];
|
|
r_temp += (int)img.at<cv::Vec3b>(i, j)[2];
|
|
}
|
|
}
|
|
b = b_temp / (img.cols * img.rows);
|
|
g = g_temp / (img.cols * img.rows);
|
|
r = r_temp / (img.cols * img.rows);
|
|
}
|
|
|
|
void Correct::cal_correction_ratio()
|
|
{
|
|
correction_ratio_b = b / b_base;
|
|
correction_ratio_g = g / g_base;
|
|
correction_ratio_r = r / r_base;
|
|
qDebug()<<"correction ratio"<<correction_ratio_b<<correction_ratio_g<<correction_ratio_r;
|
|
}
|
|
|
|
|
|
void Correct::correct_img(cv::Mat img)
|
|
{
|
|
for(int i=0; i<img.cols; i++)
|
|
{
|
|
for(int j=0; j<img.rows; j++)
|
|
{
|
|
((img.at<cv::Vec3b>(j, i)[0] * correction_ratio_b) > 255) ? img.at<cv::Vec3b>(j, i)[0] = 255 :img.at<cv::Vec3b>(j, i)[0] *= correction_ratio_b;
|
|
((img.at<cv::Vec3b>(j, i)[1] * correction_ratio_g) > 255) ? img.at<cv::Vec3b>(j, i)[1] = 255 :img.at<cv::Vec3b>(j, i)[1] *= correction_ratio_g;
|
|
((img.at<cv::Vec3b>(j, i)[2] * correction_ratio_r) > 255) ? img.at<cv::Vec3b>(j, i)[2] = 255 :img.at<cv::Vec3b>(j, i)[2] *= correction_ratio_r;
|
|
}
|
|
}
|
|
}
|