C++ 如何绘制bazier样条曲线opencv

C++ 如何绘制bazier样条曲线opencv,c++,opencv,C++,Opencv,这是我的代码,当我运行它时,它显示了一个准备好的bazier样条曲线,我不能在上面编辑它 #include "stdafx.h" #include <stdlib.h> #include <gl/glut.h> // 4 control points for our cubic bezier curve float Points[4][3] = { { 10,10,0 }, { 5,10,2 }, { -5,0,0 }, {-10,5,-

这是我的代码,当我运行它时,它显示了一个准备好的bazier样条曲线,我不能在上面编辑它

   #include "stdafx.h"
   #include <stdlib.h>
   #include <gl/glut.h>

   // 4 control points for our cubic bezier curve
   float Points[4][3] = {
{ 10,10,0 },
{  5,10,2 },
{ -5,0,0 },
{-10,5,-2}
 };

 // the level of detail of the curve
 unsigned int LOD=20;


   void OnKeyPress(unsigned char key,int,int) {
switch(key) {

// increase the LOD
case '+':
    ++LOD;
    break;

// decrease the LOD
case '-':
    --LOD;

    // have a minimum LOD value
    if (LOD<3)
        LOD=3;
    break;
default:
    break;
}

// ask glut to redraw the screen for us...
glutPostRedisplay();
  }

   void OnDraw() {

// clear the screen & depth buffer
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

// clear the previous transform
glLoadIdentity();

// set the camera position
gluLookAt(  1,10,30,    //  eye pos
            0,0,0,  //  aim point
            0,1,0); //  up direction

glColor3f(1,0,1);

// we will draw lots of little lines to make our curve
glBegin(GL_LINE_STRIP);

for(int i=0;i!=LOD;++i) {

    // use the parametric time value 0 to 1
    float t = (float)i/(LOD-1);

    // nice to pre-calculate 1.0f-t because we will need it frequently
    float it = 1.0f-t;

    // calculate blending functions
    float b0 = t*t*t;
    float b1 = 3*t*t*it;
    float b2 = 3*t*it*it;
    float b3 =  it*it*it;

    // calculate the x,y and z of the curve point by summing
    // the Control vertices weighted by their respective blending
    // functions
    //
    float x = b0*Points[0][0] +
              b1*Points[1][0] +
              b2*Points[2][0] +
              b3*Points[3][0] ;

    float y = b0*Points[0][1] +
              b1*Points[1][1] +
              b2*Points[2][1] +
              b3*Points[3][1] ;

    float z = b0*Points[0][2] +
              b1*Points[1][2] +
              b2*Points[2][2] +
              b3*Points[3][2] ;

    // specify the point
    glVertex3f( x,y,z );
}
glEnd();

// draw the Control Vertices
glColor3f(0,1,0);
glPointSize(3);
glBegin(GL_POINTS);
    for(int i=0;i!=4;++i) {
        glVertex3fv( Points[i] );
    }
glEnd();

// draw the hull of the curve
glColor3f(0,1,1);
glBegin(GL_LINE_STRIP);
    for(int i=0;i!=4;++i) {
        glVertex3fv( Points[i] );
    }
glEnd();

// currently we've been drawing to the back buffer, we need
// to swap the back buffer with the front one to make the image visible
glutSwapBuffers();
}


   void OnInit() {
// enable depth testing
glEnable(GL_DEPTH_TEST);
   }


   void OnExit() {
   }


   void OnReshape(int w, int h)
   {
if (h==0)
    h=1;

// set the drawable region of the window
glViewport(0,0,w,h);

// set up the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

   // just use a perspective projection
    gluPerspective(45,(float)w/h,0.1,100);

    // go back to modelview matrix so we can move the objects about
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
     }


   int main(int argc,char** argv) {

// initialise glut
glutInit(&argc,argv);

// request a depth buffer, RGBA display mode, and we want double buffering
glutInitDisplayMode(GLUT_DEPTH|GLUT_RGBA|GLUT_DOUBLE);

// set the initial window size
glutInitWindowSize(640,480);

// create the window
glutCreateWindow("Bezier Curve: +/- to Change Level of Detail");

// set the function to use to draw our scene
glutDisplayFunc(OnDraw);

// set the function to handle changes in screen size
glutReshapeFunc(OnReshape);

// set the function for the key presses
glutKeyboardFunc(OnKeyPress);

// run our custom initialisation
OnInit();

// set the function to be called when we exit
atexit(OnExit);

// this function runs a while loop to keep the program running.
glutMainLoop();
return 0;
   }
#包括“stdafx.h”
#包括
#包括
//三次贝塞尔曲线的4个控制点
浮点数[4][3]={
{ 10,10,0 },
{  5,10,2 },
{ -5,0,0 },
{-10,5,-2}
};
//曲线的详细程度
无符号整数LOD=20;
void OnKeyPress(无符号字符键,int,int){
开关(钥匙){
//增加LOD
格“+”:
++LOD;
打破
//降低LOD
案例'-':
--LOD;
//具有最小LOD值

如果(lod)你为什么需要OpenCV来做这件事?使用OpenGL来处理你想要编辑的鼠标事件(点击和移动),你就完成了!@Berriel好的,我怎么做?