opencv-畫線條/矩陣/圓/文字
線條
cv2.line(image, start_point, end_point, color, thickness)
參數:
image:圖像。
start_point:起始坐標,即(X坐標值,Y坐標值)。
end_point:終點坐標,即(X坐標值Y坐標值)。
color:線條的顏色。例如:(255,0,0)為藍色。
thickness:粗細像素。
圓
cv2.circle(image, center_coordinates, radius, color, thickness)參數:
image:圖像。
center_coordinates:圓的中心坐標,即(X坐標值,Y坐標值)。
radius:圓的半徑。
color:邊界線的顏色。例如:(255,0,0)為藍色。
thickness:粗細像素。厚度-1像素將以指定的顏色填充矩形形狀。
image:圖像。
center_coordinates:圓的中心坐標,即(X坐標值,Y坐標值)。
radius:圓的半徑。
color:邊界線的顏色。例如:(255,0,0)為藍色。
thickness:粗細像素。厚度-1像素將以指定的顏色填充矩形形狀。
矩陣
cv2.rectangle(image, start_point, end_point, color, thickness)參數:
image:圖像。
start_point:起始坐標。即(X坐標值,Y坐標值)。
end_point: 結束坐標。即(X坐標值ÿ坐標值)。
color: 顏色。例如:(255,0,0)為藍色。
thickness:粗細像素。厚度-1像素或cv2.FILLED將以指定的顏色填充矩形形狀。
image:圖像。
start_point:起始坐標。即(X坐標值,Y坐標值)。
end_point: 結束坐標。即(X坐標值ÿ坐標值)。
color: 顏色。例如:(255,0,0)為藍色。
thickness:粗細像素。厚度-1像素或cv2.FILLED將以指定的顏色填充矩形形狀。
文字
cv2.putText(image, text, org, font, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])
參數:
image:圖像。
text: 文本字符串。
org: 字符串左下角的坐標。
font: 字體類型。FONT_HERSHEY_PLAIN,等
fontScale: 字體大小
color: 字符串的顏色
thickness: 線的粗細像素。
lineType: 可選參數,它給出了要使用的行的類型。
bottomLeftOrigin: 可選參數。如果為true,則圖像數據原點位於左下角。否則,它位於左上角。
image:圖像。
text: 文本字符串。
org: 字符串左下角的坐標。
font: 字體類型。FONT_HERSHEY_PLAIN,等
fontScale: 字體大小
color: 字符串的顏色
thickness: 線的粗細像素。
lineType: 可選參數,它給出了要使用的行的類型。
bottomLeftOrigin: 可選參數。如果為true,則圖像數據原點位於左下角。否則,它位於左上角。
import cv2
import numpy as np
img = np.zeros((512, 512, 3), np.uint8)
# img[:] = (55, 200, 100)
print(img.shape)
# cv2.line(img, (0, 0), (512, 512), (255, 0, 0), 3)
# cv2.rectangle(img, (200, 100), (300, 512), (100, 50, 240), 2)
# cv2.rectangle(img, (0, 0), (256, 256), (100, 50, 240), cv2.FILLED)
#cv2.circle(img, (250, 250), 50, (255,200,100))
cv2.putText(img, "opencv", (100, 250), 2, cv2.FONT_HERSHEY_COMPLEX, (0, 255, 0), 2)
cv2.imshow("img", img)
cv2.waitKey(0)
留言
張貼留言