Opencv-python Drawing Basics

Source: Internet
Author: User
Tags border color polyline scalar

The correlation function is introduced in 1. Point

The data structure represents the coordinates of its image and the specified 2D point. can be defined as:

Point pt;

Pt.x = 10;

Pt.y = 8;

Or

Point pt = Point (10, 8);

2. Scalar

Represents an array with 4 elements. The secondary type is used extensively in OpenCV to pass pixel values.

In this section, we'll use it further to represent the RGB color value (three parameters). If you do not use the fourth parameter, you do not need to define it.

Let's look at an example if the following color parameter expressions are given:

Scalar (A, B, c)

Then the defined RGB color value is: Red = c, Green = B and blue= a

3. Rectangle
voidconst Scalar&color, intthickness=1,intlineType=8, intshift=0voidconst Scalar&color, intthickness=1, intlineType=8,intshift=0 )

Parameters:

img– objects that draw rectangles
pt1– a vertex of a rectangle, in the upper-left corner.
pt2– another vertex, in the lower right corner.
rec– another way to determine the rectangle, give the upper-left corner coordinate and the length-width
color– specifies the color or brightness of the rectangle (a grayscale image), and scalar (255,0,255) can be specified.
thickness– the thickness of the rectangle border. A negative value (like cv_filled) indicates that you want to draw a filled rectangle
linetype– border style. (8 (or 0)-8-connected line (8 adjacency) connector.
4-4-connected Line (4 adjacency) connector.
cv_aa-antialiased lines. )

shift– the number of decimal places in a coordinate point

4. Line
C++: void line(Mat& img, Point pt1,Point pt2, const Scalar& color, int thickness=1, int lineType=8,int shift=0)

Parameters:

img– image.
pt1– line start.
pt2– line end.
color– Line Color.
thickness– line width.
linetype– Linetype
Type of the line:

8 (or omitted)-8-connected line.
4-4-connected line.
Cv_aa-antialiased line.
shift– the number of decimal places in the coordinate point.

5. Circle
voidconst Scalar&color,intthickness=1, intlineType=8, intshift=0)

Parameters:

img– the rectangle to draw the circle.
center– the center coordinate.
radius– radius.
color– round border color, scalar type
A thickness– positive value indicates the round border width. Negative values indicate a filled circle
linetype– round border Style
shift– Center coordinates and the number of decimal places of the radius

7.Ellipse
voiddoubledoubledoubleconst Scalar& color,int thickness=1int lineType=8int shift=0voidconstint thickness=1int lineType=8)

Parameters:

img– the image where the ellipse is located.
center– Oval Center.
axes– half length of elliptical spindle
angle– Ellipse Rotation angle
startangle– Elliptical Arc Starting angle
endangle– Elliptical Arc Termination angle
box– Specifies the center of the ellipse and the rotational angle of information, either through Rotatedrect or cvbox2d. This means that the ellipse is drawn on the rotated rectangle (the rectangle is not visible, just a box is specified)
color– Oval border color.
thickness– positive values represent oval border widths, negative values represent filled ellipses
linetype– Linetype
shift– Ellipse Center coordinate and the number of decimal places of the axis

8. PolyLine
c++: void  polylines (mat& img , const  point** pts, const  int  * npts, int  ncontours, bool  isClosed, const  scalar& Color, int  thickness=1 , int  Linetype=8 , int  shift=0 ) C + +: void  polylines (inputoutputarray img, inputarrayofarrays pts, bool  isClosed, const  scalar& color, int  thickness=1 , int  Linetype=8 , int  shift=0 )  

Parameters:
The image where the img– polyline is located.
pts– the inflection point coordinate pointer in the polyline.
npts– polyline inflection point number pointer.
ncontours– the number of polyline segments.
isclosed– whether the polyline is closed.
color– the polyline color.
thickness– the polyline width.
linetype– Linetype.
shift– the number of decimal places in vertex coordinates.

9. Puttext
voidconstintdoubleint thickness=1int lineType=8bool bottomLeftOrigin=false )

Parameters:
img– Displays the image where the text is located.
text– the text you want to display.
org– the lower-left coordinate of the text in the image.
font– font structure.
fontface– font type, selectable font: Font_hershey_simplex, Font_hershey_plain, Font_hershey_duplex,font_hershey_complex, FONT_ Hershey_triplex, Font_hershey_complex_small, Font_hershey_script_simplex, Orfont_hershey_script_complex, All of the above types can be used with font_hershey_italic to produce italic effects.
fontscale– font size, this value is multiplied by the font built-in size to get the font size
color– text color
thickness– the thickness of the line, similar to the 0.38 nib and the 0.5 nib
linetype– linear.
Bottomleftorigin–true, the image data origin is in the lower left corner. Otherwise, the image data origin is in the upper left corner.

Case code
ImportNumPy asNpImportCv2img=Np.zeros (( +, +,3), np.uint8) Cv2.line (IMG, (0,0),(511,511),(255,0,0),5) Cv2.rectangle (IMG, (384,0),(510, -),(0,255,0),3) Cv2.circle (IMG, (447, the), the, (0,0,255),-1) Cv2.ellipse (IMG, ( the, the),( -, -),0,0, the,255,-1) pts=Np.array ([[Ten,5],[ -, -],[ -, -],[ -,Ten]], Np.int32) pts=Pts.reshape ((-1,1,2)) Cv2.polylines (Img,[pts],True,(0,255,255)) font=Cv2. Font_hershey_simplexcv2.puttext (IMG,' OpenCV ',(Ten, -), Font,4,(255,255,255),2, Cv2. LINE_AA) Cv2.imshow ("Image", IMG) Cv2.waitkey (0)

Run results

Opencv-python Drawing Basics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.