OpenCv:绘制一个白色填充的多边形 [英] OpenCv : draw a white filled polygon

查看:699
本文介绍了OpenCv:绘制一个白色填充的多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在黑色的IplImage中绘制任意角度的白色填充多边形.我知道存在诸如createCircle之类的函数,但是我找不到多边形类似的东西. 我发现,但是使用它很糟糕,我的意思是我不必只是为了在黑色背景上绘制一个简单的白色多边形而已!...

I'd like to draw a white filled polygon, with arbitrary angle, in a black IplImage. I know there exists function such as createCircle, but I can't find something similar for polygons. I found this , but the use of it is awful, I mean I shouldn't have to go into this just to draw one simple white polygon on a black background...!

我在OpenCV文档中找到的示例:

The example I found on the OpenCV documentation:

void MyPolygon( Mat img )
{
   int lineType = 8;

   /** Create some points */
   Point rook_points[1][20];
   rook_points[0][0] = Point( w/4.0, 7*w/8.0 );
   rook_points[0][1] = Point( 3*w/4.0, 7*w/8.0 );
   rook_points[0][2] = Point( 3*w/4.0, 13*w/16.0 );
   rook_poi /*** blablabla **/
   rook_points[0][19] = Point( w/4.0, 13*w/16.0) ;

   const Point* ppt[1] = { rook_points[0] };
   int npt[] = { 20 };

   fillPoly( img,
             ppt,
             npt,
             1,
             Scalar( 255, 255, 255 ),
             lineType );
 }

基本上,我的问题是,如何将CvBox2D放入fillPoly中,以从中获取蒙版并最终设置所需的带角度的ROI"?

Basically, my question is, how do I put a CvBox2D into fillPoly, to get a mask out of it and finally set the "ROI with angle" that I need?

推荐答案

像这样:

#include <cv.h>

void drawBox( CvArr* img, CvBox2D box, CvScalar color )
{

    CvPoint2D32f pointsf[4];
    cvBoxPoints( box , pointsf );

    CvPoint pointsi[4];

    for(int i=0;i<4;i++)
    {
        pointsi[i]=cvPointFrom32f(pointsf[i]);
    }

    CvPoint* countours[1]={
        pointsi,
    };

    int countours_n[1]={
        4,      
    };

    cvFillPoly( img, countours, countours_n, 1, color );

}

这篇关于OpenCv:绘制一个白色填充的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆