OpenCV之怀旧图片

原始图片

图片模糊

    Mat _blur;
    cv::GaussianBlur(src,_blur,Size(3,3),0);

 

图片锐化

    Mat _sharp;
    Mat kernal = Mat::zeros(3,3,CV_32FC1);
    kernal.at<float>(0,1) = -1;
    kernal.at<float>(1,0) = -1;
    kernal.at<float>(1,1) = 5;
    kernal.at<float>(1,2) = -1;
    kernal.at<float>(2,1) = -1;

    cv::filter2D(_blur,_sharp,-1,kernal);

 

降低颜色饱和度

    Mat _hsv,_sat;
    cvtColor(_sharp,_hsv,cv::COLOR_BGR2HSV);
    imwrite("d:/hsv.bmp",_hsv);
    for (int h = 0;h < _hsv.rows;h ++)
    {
        uchar *data = _hsv.ptr<uchar>(h);
        for (int w = 0;w < _hsv.cols;w ++)
        {
            int w3 = 3*w;
            data[w3 + 1] = 0.7 * data[w3 + 1];
        }
    }
    cvtColor(_hsv,_sat,cv::COLOR_HSV2BGR);

 

像素偏移

    int off = 3;
    Mat _trans = _sat.clone();
    for (int h = 0;h < _sat.rows ;h ++)
    {
        for (int w = 0;w < _sat.cols;w ++)
        {
            int nh = h + off;
            int nw = w + off;
            if (nh >= 0 && nh < _sat.rows &&
                nw >= 0 && nw < _sat.cols )
            {
                _trans.at<Vec3b>(h,w)[0] =  _sat.at<Vec3b>(h,w)[0];
                _trans.at<Vec3b>(h,w)[1] =  _sat.at<Vec3b>(h,w)[1];
                _trans.at<Vec3b>(h,w)[2] =  _sat.at<Vec3b>(nh,nw)[2];
            }
        }
    }

 

增加黄色

 

猜你喜欢

转载自blog.csdn.net/hulinhulin/article/details/133188211