貝塞爾曲線

 1 #include <stdio.h>
 2 #include <opencv/cv.h>
 3 #include <opencv/cxcore.h>
 4 #include <opencv/highgui.h>
 5 #include <math.h>
 6 
 7 long long  bazal [101][102];
 8 /************
 9 1
10 1 1
11 1 2 1
12 1 3 3 1
13 ************/
14 
15 void set_bazal()
16 {
17     for (int i = 0; i < 101; i++)
18     {
19         for (int j = 0; j < 102; j++)
20         {
21             bazal[i][j] = 1;
22         }
23     }
24     for (int i = 2; i < 101; i++)
25     {
26         for (int j = 2; j < i+1; j++)
27         {
28             bazal[i][j] = bazal[i-1][j-1] + bazal[i-1][j];
29         }
30     }
31     for (int i = 1; i < 30; i++)
32     {
33         for (int j = 1; j <= i+1; j++)
34         {
35             printf("%10ld", bazal[i][j]);
36         }
37         printf("\n");
38     }
39 }
40 
41 int main(int argc, char argv[])
42 {
43     set_bazal();
44     getchar();
45     IplImage* srcimg = cvLoadImage("Jellyfish.jpg", 1);
46     CvFont font;
47     cvInitFont(&font,CV_FONT_HERSHEY_DUPLEX ,1.0f,1.0f,0,1,CV_AA);
48     cvPutText(srcimg, "123123",cvPoint(100, 100), &font,CV_RGB(255,255,0));
49 
50     int x0 = 100;
51     int y0 = 100;
52 
53     int x1 = 300;
54     int y1 = 200;
55 
56     int x2 = 500;
57     int y2 = 20;
58 
59     int x3 = 700;
60     int y3 = 100;
61 
62 
63     for(float i = 0; i <= 1; i += 0.001 )
64     {
65         
66         CvPoint centerpoint;
67         centerpoint.x= (int)((double)(x0) * powf(i, 3) * powf(1-i, 0) * bazal[3][1] +   (double)(x1) * powf(i, 2) * powf(1-i, 1) * bazal[3][2] +   (double)(x2) * powf(i, 1) * powf(1-i, 2) * bazal[3][3] + (int)((double)(x3) * powf(i, 0) * powf(1-i, 3) * bazal[3][4]) ); 
68         centerpoint.y= (int)((double)(y0) * powf(i, 3) * powf(1-i, 0) * bazal[3][1] +   (double)(y1) * powf(i, 2) * powf(1-i, 1) * bazal[3][2] +   (double)(y2) * powf(i, 1) * powf(1-i, 2) * bazal[3][3] + (int)((double)(y3) * powf(i, 0) * powf(1-i, 3) * bazal[3][4]) ); 
69         cvCircle( srcimg, centerpoint ,1 , CV_RGB(0,255,0),1, 8, 3 );
70     }
71 
72     cvNamedWindow("srcimg");
73     cvShowImage("srcimg", srcimg);
74     cvWaitKey(0);
75     cvDestroyWindow("srcimg");
76     cvReleaseImage(&srcimg);
77     getchar();
78     return 0;
79 }

 

posted on 2016-10-13 22:11  wusichen  阅读(145)  评论(0编辑  收藏  举报