Define head function#ifndef ps_algorithm_h_included#define ps_algorithm_h_included#include <iostream># Include <string> #include "cv.h" #include "highgui.h" #include "cxmat.hpp" #include "cxcore.hpp" using namespace std Using namespace Cv;void show_image (mat&, const string &); #endif//Ps_algorithm_h_included/*this program would ge Nerate "Old picture" effect.*/#include "ps_algorithm.h" #include <time.h>using namespace std;using namespace CV; int main (void) {string Img_name ("9.jpg"); Mat image_in; Image_in=imread (Img_name); Show_image (image_in, img_name); Mat image_out (Image_in.size (), CV_32FC3); Image_in.convertto (Image_out, CV_32FC3); Mat image_2 (Image_in.size (), CV_32FC3); Image_in.convertto (image_2, CV_32FC3); Mat R (image_in.rows, Image_in.cols, CV_32FC1); Mat g (Image_in.rows, Image_in.cols, CV_32FC1); Mat B (Image_in.rows, Image_in.cols, CV_32FC1); Mat Out[]={b, G, r}; Split (image_2, out); Mat r_new (Image_in.rows, Image_In.cols, CV_32FC1); Mat g_new (Image_in.rows, Image_in.cols, CV_32FC1); Mat b_new (Image_in.rows, Image_in.cols, CV_32FC1); R_new=0.393*r+0.769*g+0.189*b; G_new=0.349*r+0.686*g+0.168*b; B_new=0.272*r+0.534*g+0.131*b; Mat rgb[]={b_new, G_new, r_new}; Merge (Rgb,3,image_out); image_out=image_out/255; Show_image (Image_out, "out.jpg"); Imwrite ("Out.jpg", image_out*255); Waitkey (); cout<< "All are well." <<endl;} #include "ps_algorithm.h" #include <iostream> #include <string>using namespace std;using namespace cv;void Show_image (mat& Image, const string& str) {Namedwindow (Str.c_str (), cv_window_autosize); Imshow (Str.c_str (), Image);}
Original
opencv--Old photo effect