• OpenCV——旋转模糊 (二)



    // 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"
    #include "math.h"
    
    using namespace std;
    using namespace cv;
    
    void Show_Image(Mat&, const string &);
    
    #endif // PS_ALGORITHM_H_INCLUDED
    
    /*
    This program will generate
    spin blur effect
    
    */
    
    
    #include "PS_Algorithm.h"
    #include <time.h>
    
    using namespace std;
    using namespace cv;
    
    int main()
    {
        string Img_name("4.jpg");
        Mat Img_in;
        Img_in=imread(Img_name);
        Show_Image(Img_in, Img_name);
    
        Mat Img_out(Img_in.size(), CV_32FC3);
        Img_in.convertTo(Img_out, CV_32FC3);
    
        int width=Img_in.cols;
        int height=Img_in.rows;
    
        int n_point=1;
    
        float angle=30;
    
        float w=angle*3.1415926/180;
        float w_2=w*w;
    
        int Num=3;
        int Num2=Num*Num;
    
    
        Point Center(width/2, height/2);
        float t1, t2, t3;
        int x1, y1;
        int x2, y2;
        int new_x, new_y;
    
        for (int y=0; y<height; y++)
        {
            for (int x=0; x<width; x++)
            {
                n_point=1;
                x1=x-Center.x;
                y1=Center.y-y;
    
                t1=Img_in.at<Vec3b>(y, x)[0];
                t2=Img_in.at<Vec3b>(y, x)[1];
                t3=Img_in.at<Vec3b>(y, x)[2];
    
                x2=x1; y2=y1;
    
                for (int mm=0; mm<Num; mm++)
                {
                    x1=x2;
                    y1=y2;
    
                    // anticlockwise
                    x2=x1-w*y1/Num-w_2*x1/Num2;
                    y2=y1+w*x1/Num-w_2*y1/Num2;
    
                    // clockwise
                    //x2=x1+w*y1/Num-w_2*x1/Num2;
                    //y2=y1-w*x1/Num-w_2*y1/Num2;
    
                    new_x=x2+Center.x;
                    new_y=Center.y-y2;
    
                    if (new_x>0 && new_x<width-1 && new_y>0 && new_y<height-1)
                    {
                        t1=t1+Img_in.at<Vec3b>(new_y, new_x)[0];
                        t2=t2+Img_in.at<Vec3b>(new_y, new_x)[1];
                        t3=t3+Img_in.at<Vec3b>(new_y, new_x)[2];
                        n_point++;
                    }
    
                }
    
                Img_out.at<Vec3f>(y, x)[0]=t1/n_point;
                Img_out.at<Vec3f>(y, x)[1]=t2/n_point;
                Img_out.at<Vec3f>(y, x)[2]=t3/n_point;
    
            }
        }
    
        Img_out=Img_out/255.0;
        Show_Image(Img_out, "out");
    
        imwrite("Out.jpg", Img_out*255);
    
    
        waitKey();
    
    }
    
    
    // define the show image
    #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);
    
    }
    
    

    原图


    效果图


  • 相关阅读:
    pandas
    高性能的异步爬虫
    组件推荐Forloop.HtmlHelpers 用来实现MVC的js加载顺序
    MVC 表单防伪,自定义提示(AntiForgery.Validate)
    Dapper 多表(三表以上)查询小技巧
    layui记录
    java websocket中的ping-pong 机制
    图像读取Exif小知识,图像扶正,还原拍摄时的角度
    关于人脸识别引擎FaceRecognitionDotNet的实例
    .NET的关于人脸识别引擎分享(C#)
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412590.html
Copyright © 2020-2023  润新知