opencv - cvpolylines如何工作

标签 opencv c-api

遵循学习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输出的点远大于窗口本身,即 Canvas
CvRect rect = { 0, 0, 600, 600 };
img = cvCreateImage( cvSize(rect.width,rect.height), 8, 3 );

点的数量级约为-1000或更高,因此如何绘制点。

最佳答案

确切地说,您不清楚要问什么。如果这些点“大约等于或大于1000”,则源图像可能很大。这些点是相对于源图像而不是窗口的。如果需要将点放入绘图窗口中,则需要自己手动缩放这些点。

关于opencv - cvpolylines如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21383179/

相关文章:

c# - C# QueryFrame 中的 EmguCV 2.3.0 返回上一个查询的帧

快速桥接 2D 数组以键入 UnsafePointer<UnsafeMutablePointer<Double>?>?

c - Lua C API : setting error source information

c++ - 在 C 中 reshape 张量

c++ - 想要从图像中获取绿色 RGB channel 时出错

opencv - 使用opencv进行颈部检测

python - 如何保存OpenCV检测到的面部

debugging - OpenCV 中 CV_32FC3 和 CV_64FC3 的区别?

python - 使用 Python v3.x 和 C API 解释 Python v2.5 代码(关于整数除法)

mysql c api限制函数