2014-01-27 41 views
0

下学习OpenCV中给出德洛内三角,我有一些麻烦理解这个片段负责绘图的镶嵌的最后一块,这里draw_subdiv_facet被馈送一个voroni边缘同时怎么做cvpolylines工作

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); 

的点是大约是-10 00或更多,那么它仍然如何绘制点。

回答

1

现在还不清楚你在问什么,确切地说。如果这些分数是'大约1000或更多',那么可能源图像是那么大。点是相对于源图像,而不是窗口。如果您需要它们以适应绘图窗口,您需要手动缩放这些点。

0

你是对的我的错。在坐标btw 0和1000的情况下,它可能会绘出200个点以上的10个点,我只是没有看到这些点而感到困惑,但他们一直在那里。谢谢。