[Explanation] Opencv Opencv drawing function and the shift parameter

Interpretation Opencv drawing function and shift parameter

There are many Opencv drawing parameters, their function is defined as follows:

1. The basic drawing functions

1.1 draw a straight line

void line
(
	InputOutputArray img, 
	Point pt1, Point pt2,
 	const Scalar& color,
 	int thickness = 1,
	 int lineType = LINE_8,
	 int shift = 0
	 );

First parameter: drawing a straight line on which
the second argument: the starting point of a straight line
third parameter: end point of line
fourth parameter: Color
fifth parameter: width, when the line width is represented by -1 when the fill pattern
sixth parameters: linear
seventh parameter: scaling parameters (described later)

1.2 ellipse

void ellipse(
	InputOutputArray img,
 	Point center, 
	Size axes,
 	double angle, 
	double startAngle,
 	double endAngle,
 	const Scalar& color, 
	int thickness = 1,
	int lineType = LINE_8,
 	int shift = 0
);

The second parameter: the center of the ellipse drawing
third parameter: the rectangular region of the ellipse major axis and a minor axis length of the boundary, draw an ellipse on a rectangular region in the
fourth parameter: the rotation angle of the ellipse
fifth parameter: Drawing elliptic starting angle
sixth parameter: drawing an elliptical end angle
when the fifth and sixth parameter is set to 0 and 360 when the ellipse is a complete revolution, or is part of an ellipse line.

1.3 round

void circle(
	InputOutputArray img,
 	Point center,
 	int radius,
 	const Scalar& color, 
	int thickness = 1,
	int lineType = LINE_8,
 	int shift = 0);

Relatively simple, do not explain the

1.4 Rectangle

void rectangle(
	CV_IN_OUT Mat& img,
 	Rect rec,
 	const Scalar& color, 
	int thickness = 1,
	int lineType = LINE_8, 
	int shift = 0
);

Relatively simple, do not explain the

1.5 Polygon

void fillPoly(
	Mat& img,
	 const Point** pts,
 	 const int* npts,
 	int ncontours,
 	const Scalar& color, 
	int lineType = LINE_8, 
	int shift = 0,
	Point offset = Point() );

The second argument: Note is a two-dimensional pointer. Representation drawing boundary point of the polygon.
The third parameter: a pointer to a dimension, represents the number of polygon boundary point
fourth parameter: the number of polygons to be drawn
eighth parameters: offset contour of all optional

Examples of specific use


 	Point p[1][5];  
	p[0][0] = Point(100, 100);
	p[0][1] = Point(100, 200);
	p[0][2] = Point(200, 300);
	p[0][3] = Point(300, 200);
	p[0][4] = Point(300, 100);
	const Point* ppt[1] = { p[0] };//多边形点集
	
	int npt[] = { 5 };//多边形点集的数量
	fillPoly(m, ppt, npt,1,Scalar(255, 0, 0), 8);

2. shift parameters

Almost behind every plot has a function of type int shift parameter, which in the end is doing it? After my tests, I discovered that shift is used for the reduced image, and center point coordinates of the line length will be scaled down, the original digital assumed as D, the digital converted is d, the specific formula is:

d = D/2shift

Tests are as follows:

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;

int main()
{

	Mat m = imread("1.png");
	circle(m, Point(300, 300), 100, Scalar(0, 0, 255), 0, 8, 0);
	circle(m, Point(300, 300), 100, Scalar(0, 0, 255), 1, 8, 1);
	circle(m, Point(300, 300), 100, Scalar(0, 0, 255), 1, 8, 3);
	
	imshow("a", m);
	waitKey(0);
	return 0;
}

The above is only the code of the offset effect is
Here Insert Picture Description
then made the following control codes, it can be seen in accordance with 2 Shift exactly coincide with the red circle multiple narrow black circle

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;

int main()
{

	Mat m = imread("1.png");

	circle(m, Point(300, 300), 100, Scalar(0, 0, 255), 0, 8, 0);
	
	circle(m, Point(300, 300), 100, Scalar(0, 0, 255), 1, 8, 1);
	circle(m, Point(300/2, 300/2), 100/2, Scalar(0, 0, 0), 1, 8, 0); //与上一个红色圈重合
	
	circle(m, Point(300, 300), 100, Scalar(0, 0, 255), 1, 8, 3);
	circle(m, Point(300 / 8, 300 / 8), 100 / 8, Scalar(0, 0, 0), 1, 8, 0);//与上一个红色圈重合
	
	imshow("a", m);
	waitKey(0);
	return 0;
}


Here Insert Picture Description

Published 14 original articles · won praise 1 · views 502

Guess you like

Origin blog.csdn.net/qq_41741344/article/details/104347443