在学习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或更多,所以它仍然是如何绘制点。
答案 0 :(得分:1)
目前还不清楚你在问什么。如果这些点是“大约1000或更多”,则源图像可能很大。这些点是相对于源图像而不是窗口。如果需要它们适合绘图窗口,您需要自己手动缩放点。
答案 1 :(得分:0)