2018 12 6形狀繪製

2021-09-02 18:48:13 字數 3264 閱讀 7048

import cv2

import numpy as np

newimageinfo =

(500

,500,3

)#元組

dst = np.zeros(newimageinfo,np.uint8)

# line

# 繪製線段 1:dst 目標資料 2:begin 線段繪製的起始位置 3:end 線段繪製的終止位置 4: color 繪製用的顏色

cv2.line(dst,

(100

,100),

(400

,400),

(0,0

,255))

# 5:line width 線的寬度

cv2.line(dst,

(100

,200),

(400

,200),

(0,255

,255),

20)# 6:線條的型別 防鋸齒化 看兩端可以明顯看出要平滑很多

cv2.line(dst,

(100

,300),

(400

,300),

(0,255,0

),20,cv2.line_aa)

# 繪製三角形

cv2.line(dst,

(100

,150),

(50,250),

(25,100

,255))

cv2.line(dst,(50

,250),

(400

,380),

(25,100

,255))

cv2.line(dst,

(400

,380),

(100

,150),

(25,100

,255))

cv2.imshow(

'dst'

,dst)

cv2.waitkey(

0)

import cv2

import numpy as np

newimageinfo =

(500

,500,3

)#元組

dst = np.zeros(newimageinfo,np.uint8)

# 矩形繪製方法 1:dst 目標影象資料 2:左上角 3:右下角 4:顏色 5:內容是否填充 -1:填充 0<:線條加寬

cv2.rectangle(dst,(50

,100),

(200

,300),

(255,0

,0),

0)# 圓形繪製方法 2:center 圓心的位置 3:r 半徑 4:顏色 5:內容是否填充 -1:填充 0<:線條加寬

cv2.circle(dst,

(250

,250),

(50),

(0,255,0

),2)

# 圓弧的繪製方法 2:center 圓心的位置 3:兩個軸線的長度 4:angle 偏轉角度 5:begin圓弧的起始角度 6:end終止角度 7:顏色 8:內容是否填充 -1:填充 0<:線條加寬

cv2.ellipse(dst,

(256

,256),

(150

,100),

0,0,

180,

(255

,255,0

),-1

)# 繪製任意多邊形

points = np.array([[

150,50]

,[140,

140],[

200,

170],[

250,

250],[

150,50]

],np.int32)

print

(points.shape)

# 維度轉換

points = points.reshape((-

1,1,

2))print

(points.shape)

cv2.polylines(dst,

[points]

,true,(

0,255,

255)

)cv2.imshow(

'dst'

,dst)

cv2.waitkey(

0)

'''

# 文字的繪製

# 1:dst 2:文字內容 3:座標 4:字型 5:字型大小 6:color 7:粗細 8:line type

cv2.puttext(img,'this is flow',(100,300),font,1,(200,100,255),2,cv2.line_aa)

cv2.imshow('dst',img)

cv2.waitkey(0)

'''# 繪製

0)

哼哼 今天 就不寫總結

canvas繪製形狀

1.1 繪製形狀 1.1.1 繪製矩形 ctx.rect startx,starty,width,height ctx.strokerect startx,starty,width,height ctx.fillrect startx,starty,width,height ctx.clearrec...

繪製形狀和文字

繪製點 point 繪製線lint 繪製矩形 rectangle 繪製圓形 circle 繪製橢圓 或者弧線 ellipse 繪製多邊形 繪製填充多邊形 繪製文字 puttext 注 字型為 font 或 qt font 備註 linttype line aa 消除鋸齒 隨機生成線 for int ...

07 繪製形狀與文字

繪製形狀與文字 cv point資料結構 代表了乙個點的座標,乙個二維點的座標 point表示2d平面上乙個點x,y point p p.x 10 p.y 8 orp point 10,8 cv scalar資料結構 代表顏色的向量,rgb色彩空間經常是數有三個值或者灰度影象賦給乙個值 scalar...