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

}







posted on 2015-10-04 14:54  未雨愁眸  阅读(141)  评论(0编辑  收藏  举报