描述:首先,加载一张照片进内存,然后将内存里的rgb色彩转化到HSV色彩空间,调整V(value)明度。每个语句有详细注释!
源代码
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
// 声明函数
void getEveryPixels(Mat& inputImage,Mat &outputImage,int dev);
int main(int argc, char** argv )
{
// 读取照片
Mat imgage_in = imread("3.jpeg",1);
// 预定义另外色彩空间的变量
Mat image_out_withHSV;
// Mat image_out_withHSI;
// 转化色彩空间到HSV色彩空间
cvtColor(imgage_in, image_out_withHSV, COLOR_BGR2HSV);
// cvtColor(imgage_in, image_out_withHSI, COLOR_BGR2HLS);
// RGB色彩空间展示
namedWindow("image_in_withRGB");
// HSV色彩空间展示
namedWindow("image_out_withHSV");
// 将图像转换到HSI色彩空间
// namedWindow("image_out_withHSI");
// 将HSV色彩空间的明度提升50
getEveryPixels(image_out_withHSV,image_out_withHSV,50);
// 显示图像
imshow("image_in_withRGB",imgage_in);
imshow("image_out_withHSV",image_out_withHSV);
// imshow("image_out_withHSI",image_out_withHSI);
waitKey(0);
printf("end of all");
return 0;
}
/**
* 遍历像素,将明度分量提高dev个数值
* */
void getEveryPixels(Mat& inputImage,Mat &outputImage,int dev){
namedWindow("show",WINDOW_AUTOSIZE);
imshow("show",inputImage);
outputImage = inputImage.clone();
int rowNumbers = outputImage.rows;
int cloNumbers = outputImage.cols;
for (int i = 0; i < rowNumbers; i++)
{
for (int j = 0; j < cloNumbers; j++)
{
// H Hue 色调
// outputImage.at<Vec3b>(i,j)[0] = ;
// S Saturation 饱和度
// outputImage.at<Vec3b>(i,j)[1] = ;
// v Value 明度
outputImage.at<Vec3b>(i,j)[2] += dev;
}
}
}