OpenCV之怀旧图片

原始图片

OpenCV之怀旧图片_第1张图片

图片模糊

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

OpenCV之怀旧图片_第2张图片 

图片锐化

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

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

OpenCV之怀旧图片_第3张图片 

 

降低颜色饱和度

    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(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);

OpenCV之怀旧图片_第4张图片 

像素偏移

    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(h,w)[0] =  _sat.at(h,w)[0];
                _trans.at(h,w)[1] =  _sat.at(h,w)[1];
                _trans.at(h,w)[2] =  _sat.at(nh,nw)[2];
            }
        }
    }

OpenCV之怀旧图片_第5张图片 

增加黄色

OpenCV之怀旧图片_第6张图片 

你可能感兴趣的:(OpenCV,图像视频处理,opencv,人工智能,计算机视觉)