#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<iostream>
#include<stdio.h>
cv::Mat inverseColor(cv::Mat srcImage){
cv::Mat tempImage = srcImage.clone();
int row = tempImage.rows;
int col = tempImage.cols;
//对各个像素遍历进行取反
for (int i = 0; i < row;i++){
for (int j = 0; j < col; j++){
//分别对各个通道进行反色处理
tempImage.at<cv::Vec3b>(i, j)[0] = 255 - tempImage.at<cv::Vec3b>(i, j)[0];
tempImage.at<cv::Vec3b>(i, j)[1] = 255 - tempImage.at<cv::Vec3b>(i, j)[1];
tempImage.at<cv::Vec3b>(i, j)[2] = 255 - tempImage.at<cv::Vec3b>(i, j)[2];
}
}
return tempImage;
}
int main(int argc, char** argv){
cv::Mat srcImage,desIamge;
srcImage = cv::imread("..\\images\\Jay.png");
desIamge = inverseColor(srcImage);
cv::imshow("反色",desIamge);
cv::waitKey(0);
return 0;
}