老照片

来源:互联网 发布:淘宝众筹买东西靠谱吗 编辑:程序博客网 时间:2024/04/29 16:22
#include<opencv2\opencv.hpp>#include<core\core.hpp>#include<highgui\highgui.hpp>using namespace cv;using namespace std;int main() {Mat img = imread("D://图片//5.jpg");if (!img.data)return -1;img.convertTo(img, CV_32F);Mat result = img.clone();for (int i = 0; i < img.rows; i++) {float *p = img.ptr<float>(i);float *n = result.ptr<float>(i);for (int j = 0; j < img.cols; j++) {n[j * 3 + 0] = p[j * 3 + 0] * 0.131 + p[j * 3 + 1] * 0.534 + p[j * 3 + 2] * 0.272;n[j * 3 + 1] = p[j * 3 + 0] * 0.168 + p[j * 3 + 1] * 0.686 + p[j * 3 + 2] * 0.349;   n[j * 3 + 2] = p[j * 3 + 0] * 0.189 + p[j * 3 + 1] * 0.769 + p[j * 3 + 2] * 0.393;}}result.convertTo(result, CV_8U);imshow("result", result);waitKey(0);destroyAllWindows;return 0;}

效果:


0 0
原创粉丝点击