directory

    • 1. Line function
    • 2. Circle functions
    • Rectangle and Rect functions
    • 4. Ellipse function
    • 5. Polylines function
    • 6. Randomly initialize colors
    • 7, putText function
    • conclusion

1. Line function

line(img,(0.0), (511.511), (255.0.0),5)
Copy the code

This function takes 5 parameters, img is the name of the image, the starting coordinates, the ending coordinates, (255,0,0) is blue, 5 is the width of the line and it will draw a blue line from the top left to the bottom right.

2. Circle functions

cvCircle(CvArr* img, CvPoint center, int radius, CvScalar color, int thickness=1, int lineType=8, Int shift=0) img is the source image pointer, center is the coordinates of the center of the circle. Radius is the radius of the circle. Color is the color of the circle. Otherwise, indicates whether the circle is filled with line_type line type. The default is 8 shift the number of decimal places for the center point and radius value

for (int i = 0; i < points.size(); i++) { circle(image, points[i],5, Scalar(0.0.255), 2.8.0);
}
Copy the code

Rectangle and Rect functions

The Rectangle function is used to draw a rectangle, usually for marking images.

rectangle(img2, Point(j,i), Point(j + img4.cols, i + img4.rows), Scalar(255.255.0), 2.8);
Copy the code

3 represents the angular coordinates of the upper left and lower right rectangle. Scalar: Color 2 represents the width of the line. 8 is linear, and the default value is 8

The Rect function is also drawn as a rectangle, but it is different

Rect roi_rect = Rect(128.128, roi.cols, roi.rows);
Copy the code

Rect(x,y,width,height), x,y is the top left coordinates,width,height is the length and width.

4. Ellipse function

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);

ellipse(img,(256.256), (100.50),0.0.180.255.- 1)
Copy the code

This function takes 8 parameters: image name, center point coordinates, long axis length, short axis length, rotation Angle, the part of the image that appears (clockwise the long axis starting Angle and ending Angle) 0,180 is the lower half of the ellipse, color array here 255 is blue, line width ellipse elements: 1. Is the position coordinate of the center point 2. The length of the major axis and the minor axis 3. The Angle of the ellipse rotating counterclockwise 4. The starting and ending angles of the long axis clockwise

5. Polylines function

To draw polylines(SRC, [points], True,color, thickness), points is the set of points, and you need to know the set of vertices of the polygon

6. Randomly initialize colors

Here we use the random class RNG as follows:

RNG g_rng(12345);
Scalar color = Scalar(g_rng.uniform(0.255),g_rng.uniform(0.255), g_rng.uniform(0.255));/ / arbitrary value
Copy the code

7, putText function

Cv2.puttext (SRC, STR, (x0,y0), font, size, color, thickness, linetype) we need to comment the image, putText() is extremely important. Draw images, text, position coordinates, font, font size, font color, font thickness and linetype. It is recommended to use cv2.LINE_AA for linetype. For font and openCV supported fonts, look at the renderings of different styles. Serrated edges), the first type is usually enough.

conclusion

Since you’ve been using these functions a lot lately, make a note of them and come back to the blog to save time.


Reference links:

Blog.csdn.net/weixin_4349… Blog.csdn.net/weixin_4349… www.cnblogs.com/yujiachen/p… www.cnblogs.com/mld-code-li… Blog.csdn.net/bigat/artic…