OpenCV學習 繪製貝賽爾曲線

2021-09-06 07:04:16 字數 1511 閱讀 7503

出處:

// trainingtools.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include #include #include #include #include #include using namespace std;

const int ww_max_mark_count = 40; //最大40個控制點

int mark_count =4;

int conner_pt_index =-1;

cvpoint3d32f control_pts[ww_max_mark_count];

iplimage *image = 0 ; //原始影象

bool is_showcontrollines = true;

// 兩個向量相加,p=p+q

cvpoint3d32f pointadd(cvpoint3d32f p, cvpoint3d32f q)

// 向量和標量相乘p=c*p

cvpoint3d32f pointtimes(float c, cvpoint3d32f p)

// 計算貝塞爾方程的值

// 變數u的範圍在0-1之間

//p1*t^3 + p2*3*t^2*(1-t) + p3*3*t*(1-t)^2 + p4*(1-t)^3 = pnew

cvpoint3d32f bernstein(float u, cvpoint3d32f *p)

//畫控制線

void drawcontrolline(cvpoint3d32f *p)

cvline(image,pc[0],pc[1],cv_rgb(0,0,255),1,cv_aa,0);

cvline(image,pc[2],pc[3],cv_rgb(0,0,255),1,cv_aa,0);

}//得到最近control_pts的index

int getnearpointindex(cvpoint mouse_pt)}}

} else if ( event == cv_event_mousemove ) //修改控制點座標

}};int main(int argc, char* argv)

//畫控制線

if(is_showcontrollines)drawcontrolline(pcontrols);

pcontrols+=3;

}cvshowimage("win",image);

int keycode = cvwaitkey(20);

if (keycode==27) break;

if(keycode=='w'||keycode=='w') divs+=2;

if(keycode=='s'||keycode=='s') divs-=2;

if(keycode=='z'||keycode=='z') is_showcontrollines = is_showcontrollines^1;

//cout<<"precision : "<

貝賽爾曲線

貝塞爾曲線又稱貝茲曲線或貝濟埃曲線,一般的向量圖形軟體通過它來精確畫出曲線,貝茲曲線由線段與節點組成,節點是可拖動的支點,線段像可伸縮的皮筋,我們在繪圖工具上看到的鋼筆工具就是來做這種向量曲線的。當然在一些比較成熟的點陣圖軟體中也有貝塞爾曲線工具,如photoshop等。在flash4中還沒有完整的...

繪製貝塞爾Bezier曲線

trainingtools.cpp 定義控制台應用程式的入口點。include include include include include include using namespace std const int ww max mark count 40 最大40個控制點 int mark c...

OPENGL繪製貝塞爾曲線

最終效果圖 通過3個點形成一條貝塞爾曲線 1.滑鼠問題 在使用滑鼠獲取座標的時候,要知道滑鼠獲取的座標和螢幕座標是不同的 opengl使用右手座標 從左到右,x遞增 從下到上,y遞增 從遠到近,z遞增 而滑鼠是從左到右增x,同時從上到下也是增y 所以在求 y 的時候,用 螢幕大小 y 來獲取 2.繪...