• 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 the garland.
    
    */
    
    #include "PS_Algorithm.h"
    #include <time.h>
    
    using namespace std;
    using namespace cv;
    
    #define pi 3.1415926
    
    int main()
    {
    
        Mat Img(400,600, CV_32FC3);
    
        int width=Img.cols;
        int height=Img.rows;
    
        Point Center(width/2, height/2);
    
        int k=4;
        int N=720;
        float R=150.0;
        float dn;
    
        dn=360.0/N;
        float theta;
        float r;
        float x,y;
        float new_x, new_y;
    
        for (int i=0; i<=N; i++)
        {
            theta=(i*dn)*pi/180.0;
            r=R*sin(k*theta);
            x=(r*cos(theta));
            y=(r*sin(theta));
            new_y=(int)(Center.y-y);
            new_x=(int)(Center.x+x);
            Img.at<Vec3f>(new_y, new_x)[0]=1;
            Img.at<Vec3f>(new_y, new_x)[1]=1;
            Img.at<Vec3f>(new_y, new_x)[2]=1;
    
        }
    
        Show_Image(Img, "out");
    
        imwrite("Out.jpg", Img*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);
    
    }
    







  • 相关阅读:
    【题解】B进制星球
    高斯消元
    7.16
    题解 P1572 【计算分数】
    7.30
    7.31
    项目中使用 MyBatis(一)
    从整体上了解Spring MVC
    Spring注解
    Spring IOC 和 DI
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412576.html
Copyright © 2020-2023  润新知