常見參數:
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()