安装完opencv后,下面就要尝试一下。
首先感谢一下前人的经验,我参考了的代码,
稍作修改,将其变成一个小工具,可将图片加“怀旧色”滤镜保存输出。
不说废话,直接上代码。
#include#include using namespace cv;using namespace std;int main(int argc, char ** argv){ // input args check if(argc < 3){ printf("please input args.\n"); printf("e.g. : ./test infilepath outfilepath \n"); return 0; } char * input = argv[1]; char * output = argv[2]; printf("input: %s, output: %s\n", input, output); Mat src = imread(input, 1); int width=src.cols; int heigh=src.rows; RNG rng; Mat img(src.size(),CV_8UC3); for (int y=0; y (y); uchar* P1 = img.ptr (y); for (int x=0; x 255)newB=255; if(newG<0)newG=0; if(newG>255)newG=255; if(newR<0)newR=0; if(newR>255)newR=255; P1[3*x] = (uchar)newB; P1[3*x+1] = (uchar)newG; P1[3*x+2] = (uchar)newR; } } //imshow("out",img); waitKey(); imwrite(output,img);}
编译时需要注意一下,需要加上`pkg-config opencv --libs --cflags opencv`
例如:g++ -o test opencvtest.cpp `pkg-config opencv --libs --cflags opencv`
OK,编译正常。
从网上下个图片,做个测试。
看下效果,还不错。
原图:
处理后:
个人博客同步: