0

在学习opencv中给出的delaunay三角剖分之后,我在理解这个片段时遇到了一些麻烦,它是负责绘制曲面细分的最后一块,这里draw_subdiv_facet一次被喂一个voroni边缘

static void draw_subdiv_facet( IplImage* img, CvSubdiv2DEdge edge )
{
    CvSubdiv2DEdge t = edge;
    int i, count = 0;

    //cvpoint structure
    //param x:  x-coordinate of the point.
    //param y:  y-coordinate of the point.
    //param point:  the point to convert.
    CvPoint* buf = 0;

    // count number of edges in facet
    do
    {
        count++;
        t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
    } while (t != edge );
    cout<<"\ncount is : "<<count<<endl;

    //allocate the array
    buf = (CvPoint*)malloc( count * sizeof(buf[0]));

    // gather points
    t = edge;
    for( i = 0; i < count; i++ )
    {
        //
        CvSubdiv2DPoint* pt = cvSubdiv2DEdgeOrg( t );          
        if( !pt ) break;


        buf[i] = cvPoint( cvRound(pt->pt.x), cvRound(pt->pt.y));
        cout<<"pt.x is : "<<cvRound(pt->pt.x);
        cout<<"   pt.y is : "<<cvRound(pt->pt.y)<<endl;
        cout<<"converted to cvPoint gives"<<buf[i].x<<" , "<<buf[i].y<<endl;
        t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
    }

    if( i == count )   
    {
        CvSubdiv2DPoint* pt = cvSubdiv2DEdgeDst( cvSubdiv2DRotateEdge( edge, 1 ));
        //cvFillConvexPoly( img, buf, count, CV_RGB(rand()&255,rand()&255,rand()&255), CV_AA, 0 );


        CvPoint xx = buf[0];
        cout<<"located at "<<xx.x<<","<<xx.y<<endl;
        cvPolyLine( img, &buf, &count, 1, 1, CV_RGB(0,0,0), 1, CV_AA, 0);
        draw_subdiv_point( img, pt->pt, CV_RGB(0,0,0));
    }
    free( buf );
}

如您所见,这负责在多边形中绘制线条和着色,但是 cout 输出的点比窗口本身大得多,即画布是

CvRect rect = { 0, 0, 600, 600 };
img = cvCreateImage( cvSize(rect.width,rect.height), 8, 3 );

这些点的数量级为-1000或更多,所以它仍然如何绘制点。

4

2 回答 2

1

目前还不清楚你在问什么,确切地说。如果这些点是“大约 1000 个或更多”,那么源图像可能就是那么大。这些点相对于源图像,而不是窗口。如果您需要它们适合绘图窗口,则需要自己手动缩放这些点。

于 2014-01-27T15:33:28.067 回答
0

你是对的我的错误。它正在绘制坐标 btw 0 和 1000 的 200 多个点中的 10 个,我只是没有看到这些点并且感到困惑,但它们一直都在那里。谢谢。

于 2014-01-27T18:05:47.630 回答