2014-01-27 64 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個點,我只是沒有看到這些點而感到困惑,但他們一直在那裏。謝謝。