代码如下:
#include <opencv2/opencv.hpp>
#include <iostream>
#include <direct.h>
using namespace cv;
using namespace std;
int main()
{
Mat src = cv::imread("bin\\图片库\\Test1.jpg");//原图的分辨率是Rows:756,Cols:1008;
Mat dst;
src.copyTo(dst);
// 获取图像宽、高
int channels = src.channels();
int rows = src.rows;
int cols = src.cols * channels;
if (src.isContinuous()) {
cols *= rows;
rows = 1;
}
// 每个像素点的每个通道255取反
uchar* p1;
uchar* p2;
for (int row = 0; row < rows; row++) {
p1 = src.ptr<uchar>(row);// 获取像素指针
p2 = dst.ptr<uchar>(row);
for (int col = 0; col < cols; col++) {
*p2 = 255 - *p1; // 取反
p2++;
p1++;
}
}
imshow("src", src);
imshow("dst", dst);
//int a = dst.type();
waitKey(0);
return 0;
}
网友评论