import cv2
import numpy as np
img = np.zeros((500,500,3),np.uint8)
#画直线
cv2.line(img,(0,250),(250,400),(233,233,233),2)
"""
def line(img, pt1, pt2, color, thickness=None, lineType=None, shift=None):
@param img Image.
. @param pt1 First point of the line segment.
. @param pt2 Second point of the line segment.
. @param color Line color.
. @param thickness Line thickness.
"""
cv2.imshow("img",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
画矩形
画任意多边形
# 任意多边形
rect = np.array([[[200,200],[300,400],[100,400],[300,250]]],np.int32)
cv2.fillPoly(img,rect,(233,43,0)) # 可以填充
cv2.polylines(img,rect,1,(233,43,0)) # 无法填充
cv2.imshow('renyiduobianxing',img)
画圆形
import cv2
import numpy as np
img = np.zeros((500,500,3),np.uint8)
cv2.circle(img,(255,255),100,(21,123,0),-1)
cv2.circle(img,(100,100),100,(32,43,232),2,shift = 1)
cv2.imshow('circle',img)
cv2.waitKey()
cv2.destroyAllWindows()
画矩形
#画矩形
import cv2
import numpy as np
img = np.zeros((500,500,3),np.uint8)
cv2.rectangle(img,(100,100),(300,300),(100,100,100))
cv2.imshow('rectangel',img)
cv2.waitKey()
cv2.destroyAllWindows()
"""
def rectangle(img, pt1, pt2, color, thickness=None, lineType=None, shift=None)
. @param img Image.
. @param pt1 Vertex of the rectangle.
. @param pt2 Vertex of the rectangle opposite to pt1 .
. @param color Rectangle color or brightness (grayscale image).
. @param thickness Thickness of lines that make up the rectangle. Negative values, like #FILLED,
. mean that the function has to draw a filled rectangle.
. @param lineType Type of the line. See #LineTypes
. @param shift Number of fractional bits in the point coordinates.
"""
画椭圆
ellipse()
import cv2
import numpy as np
img = np.zeros((500,500,3),np.uint8)
cv2.ellipse(img,(250,250),(50,30),0,0,360,(100,200,200),2)
"""
def ellipse(img, center, axes, angle, startAngle, endAngle, color, thickness=None, lineType=None, shift=None)
@param img Image.
. @param center Center of the ellipse.
. @param axes Half of the size of the ellipse main axes.
. @param angle Ellipse rotation angle in degrees.
. @param startAngle Starting angle of the elliptic arc in degrees.
. @param endAngle Ending angle of the elliptic arc in degrees.
. @param color Ellipse color.
. @param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that
. a filled ellipse sector is to be drawn.
. @param lineType Type of the ellipse boundary. See #LineTypes
. @param shift Number of fractional bits in the coordinates of the center and values of axes.
"""
cv2.imshow('ellipse',img)
cv2.waitKey()
cv2.destroyAllWindows()
添加文字文本
import cv2
import numpy as np
img = np.zeros((500,500,3),np.uint8)
cv2.putText(img,"hello OPENCV",(100,100),cv2.FONT_HERSHEY_SIMPLEX,1,(233,233,233))
"""
def putText(img, text, org, fontFace, fontScale, color, thickness=None, lineType=None, bottomLeftOrigin=None):
@param img Image.
. @param text Text string to be drawn.
. @param org Bottom-left corner of the text string in the image.
. @param fontFace Font type, see #HersheyFonts.
. @param fontScale Font scale factor that is multiplied by the font-specific base size.
. @param color Text color.
. @param thickness Thickness of the lines used to draw a text.
. @param lineType Line type. See #LineTypes
. @param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise,
. it is at the top-left corner.
"""
cv2.imshow('text',img)
cv2.waitKey()
cv2.destroyAllWindows()



