laterSon
laterSon

Reputation: 303

OpenCV rectangle draw function

OpenCV facilitates drawing rectangle provided the top-left corner and bottom-right corner of rectangle. I wanted to know which algorithm is uses to draw the rectangle, for example, all polygon filling algorithms that I know of, fills the entire polygon, i.e. boundary fill algorithm etc.
I didn't find any color filling algorithm that fills only the boundary. Please, write if I missed something or if there is such algorithm.

Upvotes: 0

Views: 213

Answers (1)

Bal Krishna Jha
Bal Krishna Jha

Reputation: 7206

from source code:

void rectangle( InputOutputArray _img, Point pt1, Point pt2,
                const Scalar& color, int thickness,
                int lineType, int shift )
{
    CV_INSTRUMENT_REGION()
Mat img = _img.getMat();

if( lineType == CV_AA && img.depth() != CV_8U )
    lineType = 8;

CV_Assert( thickness <= MAX_THICKNESS );
CV_Assert( 0 <= shift && shift <= XY_SHIFT );

double buf[4];
scalarToRawData(color, buf, img.type(), 0);

Point2l pt[4];

pt[0] = pt1;
pt[1].x = pt2.x;
pt[1].y = pt1.y;
pt[2] = pt2;
pt[3].x = pt1.x;
pt[3].y = pt2.y;

if( thickness >= 0 )
    PolyLine( img, pt, 4, true, buf, thickness, lineType, shift );
else
    FillConvexPoly( img, pt, 4, buf, lineType, shift );
}

here,we can see that if thickness is passed it draws rectangle using PolyLine.

Upvotes: 2

Related Questions