opencv像素取反函数
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat src;
src=imread("图片存储位置");
if(!src.data)
{
printf("comld not the picture");
}
Mat dst;
bitwise_not(src,dst,);
namedWindow ("dst_show",CV_WINDOW_AUTOSIZE );
imshow("dst_show",dst);
Mat dst3;
dst3=Mat (src.size(),src.type());
for(int i=0;i<src.cols;i++)
for(int j;j<rows;j++)
{
if(src.channel()==1)
{
int gray=src.at<uchar>(i,j);
dst3.at<uchar>(i,j)=255-gray;
}else if(src.channel()==3)
{
int b=src.at<Vec3b>(i,j)[0];
int g=src.at<Vec3b>(i,j)[1];
int r=src.at<Vec3b>(i,j)[2];
dst3.at<Vec3b>(i,j)[0]=255-b;
dst3.at<Vec3b>(i,j)[1]=255-g;
dst3.at<Vec3b>(i,j)[2]=255-r;
}
}
namedWindow ("dst3_show",CV_WINDOW_AUTOSIZE );
imshow("dst3_show",***);
waitKey(0);
return 0;
}