zoukankan      html  css  js  c++  java
  • 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);
    
    }
    







  • 相关阅读:
    <11>改变图像的尺寸,方便上传服务器
    <10>获取当前时间
    <09>获得字符串的size
    <08>时间戳的转换
    <07>手机号码验证
    <06>邮箱的验证
    <05>判断字符串是否为空
    WKWebView的一些知识
    objc_setAssociatedObject 使用
    linker command failed with exit code 1 (use -v to see invocation) 编译报错原因
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412576.html
Copyright © 2011-2022 走看看