常见参数:
color:颜色(255,255,0),BGR表示
thickness:线宽px,-1代表填充
linetype:圆边界类型。cv.LINE_4,cv.LINE_8,cv.LINE_AA,AA代表抗锯齿线
shift:图形缩小倍数
线
常见函数:
cv.arrowedLine() 箭头线
cv.arrowedLine(img, pt1, pt2, color[, thickness[, line_type[, shift[, tipLength]]]])
pt1:箭头起点(x,y)
pt2:箭头终点(x,y)
tipLength:
import numpy as np import cv2 as cv # Create a black image img = np.zeros((512, 512, 3), np.uint8) cv.arrowedLine(img, (0, 0), (255, 255), (255, 255, 255)) # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL cv.namedWindow('circle', cv.WINDOW_NORMAL) # 显示图像 cv.imshow('circle', img) cv.waitKey(0) cv.destroyAllWindows()
cv.line() 直线
cv.line(img, pt1, pt2, color[, thickness[, lineType[, shift]]])
pt1:起点(x,y)
pt2:终点(x,y)
import numpy as np import cv2 as cv # Create a black image img = np.zeros((512, 512, 3), np.uint8)
cv.line(img, (255, 255), (274, 274), (240, 240, 240), 10) # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL cv.namedWindow('circle', cv.WINDOW_NORMAL) # 显示图像 cv.imshow('circle', img) cv.waitKey(0) cv.destroyAllWindows()
圆
常见函数:
cv.circle() 圆
cv.circle(img, center, radius, color[, thickness[, lineType[, shift]]])
img:
center:圆心(x,y)
radius:半径 int
import numpy as np import cv2 as cv # Create a black image img = np.zeros((512, 512, 3), np.uint8) cv.circle(img, (447, 63), 63, (255, 255, 255), -1) # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL cv.namedWindow('circle', cv.WINDOW_NORMAL) # 显示图像 cv.imshow('circle', img) cv.waitKey(0) cv.destroyAllWindows()
矩形
常见函数
cv.rectangle
cv.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]])
pt1:对角,左上点
pt2:对角,右下点
import numpy as np import cv2 as cv # Create a black image img = np.zeros((512, 512, 3), np.uint8) cv.rectangle(img, ((10, 10), (40, 40)), (255, 255, 255)) # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL cv.namedWindow('circle') # 显示图像 cv.imshow('circle', img) cv.waitKey(0) cv.destroyAllWindows()
其它
常见函数
cv.drawMarker() 在指定点出标记
cv.drawMarker(img, position, color[, markerType[, markerSize[, thickness[, line_type]]]])
position:点位置 (x,y)
markerType:标记类型
import numpy as np import cv2 as cv # Create a black image img = np.zeros((512, 512, 3), np.uint8) cv.drawMarker(img, (260, 260), (255, 255, 255) # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL cv.namedWindow('circle') # 显示图像 cv.imshow('circle', img) cv.waitKey(0) cv.destroyAllWindows()
cv.putText() 绘制文本字符串
cv.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])
org:位置
text:字符串内容
fontFace:
fontScale:字体缩放倍数
bottomLeftOrigin:true:。false:反转。
import numpy as np import cv2 as cv # Create a black image img = np.zeros((512, 512, 3), np.uint8) # cv.circle(img, (447, 63), 63, (255, 255, 255), -1) # cv.arrowedLine(img, (0, 0), (255, 255), (255, 255, 255)) # cv.drawMarker(img, (260, 260), (255, 255, 255) ) # cv.line(img, (255, 255), (274, 274), (240, 240, 240), 10) cv.putText( img, "opencv", (200, 200), cv.FONT_HERSHEY_PLAIN, 1, (255, 255, 255)) # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL cv.namedWindow('circle') # 显示图像 cv.imshow('circle', img) cv.waitKey(0) cv.destroyAllWindows()