日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

Python-OpenCV 笔记7 -- 绘图(Draw)

發(fā)布時(shí)間:2025/3/12 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python-OpenCV 笔记7 -- 绘图(Draw) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Python-OpenCV 筆記7 – 繪圖(Draw)


1、畫(huà)直線 – cv2.line()


函數(shù)原型:

cv2.line(img, pt1, pt2, color[, thickness[, lineType[, shift]]])
  • img:需要繪制的圖像
  • pt1:直線的起點(diǎn)(x, y)
  • pt1:直線的終點(diǎn)(x, y)
  • color:線的顏色(x, x, x)
  • thickness:線的粗細(xì),
  • lineType:線型,cv2.FILLED、cv2.LINE_4、cv2.LINE_8

實(shí)例:

cv2.line(img,(0,0),(500,500),(255,0,0),2) cv2.imshow('畫(huà)直線', img)

2、畫(huà)矩形 – cv2.rectangle()


函數(shù)原型:

cv2.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]])
  • pt1:矩形左上角點(diǎn)(x, y)
  • pt1:直線右下角點(diǎn)(x, y)
  • thickness:寬度大于0,標(biāo)識(shí)邊線寬度;小于0,畫(huà)實(shí)心矩形

實(shí)例:

cv2.rectangle(img,(100,50),(200,150),(0,255,0),3) cv2.imshow('畫(huà)矩形', img)

3、畫(huà)圓 – cv2.circle()


函數(shù)原型:

cv2.circle(img, center, radius, color[, thickness[, lineType[, shift]]])
  • center:圓心(x, y)
  • radius:半徑 x
  • thickness:寬度大于0,標(biāo)識(shí)邊線寬度;小于0,畫(huà)實(shí)心圓

實(shí)例:

cv2.circle(img, (200,200), 50, (0,0,255), -1) cv2.imshow('畫(huà)圓', img)

4、畫(huà)橢圓 – cv2.ellipse()


函數(shù)原型:

cv2.ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[, lineType[, shift]]])
  • center:橢圓心(x, y)
  • axes:橢圓長(zhǎng)短半軸長(zhǎng) (l, s)
  • angle:橢圓相對(duì)于x軸的旋轉(zhuǎn)角度
  • startAngle:橢圓起始角度
  • endAngle:橢圓的終止角度
  • thickness:寬度大于0,標(biāo)識(shí)邊線寬度;小于0,畫(huà)實(shí)心橢圓

實(shí)例:

cv2.ellipse(img, (256,256), (100,50), 0, 0, 180, 255, -1) cv2.imshow('畫(huà)橢圓', img)

5、畫(huà)多邊形 – cv2.polylines()


函數(shù)原型:

cv2.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]])
  • pts:多邊形的拐點(diǎn),numpy 數(shù)組
  • isClosed:多邊形是否要閉合
  • thickness:寬度大于0,標(biāo)識(shí)邊線寬度;小于0,畫(huà)實(shí)心多邊形

實(shí)例:

pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32) pts = pts.reshape((-1,1,2)) cv2.polylines(img,[pts],True,(0,255,255)) cv2.imshow('畫(huà)多邊形', img)

6、畫(huà)文字 – cv2.putText()


函數(shù)原型:

cv2.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])
  • text:文字的字符串
  • org:文字放置位置的左下點(diǎn)(x, y)
  • fontFace:字體類(lèi)型
    • cv2.FONT_HERSHEY_SIMPLEX:正常尺寸的sans-serif字體
    • cv2.FONT_HERSHEY_SPLAIN:小尺寸的sans-serif字體
    • cv2.FONT_HERSHEY_COMPLEX:正常尺寸的serif字體
    • cv2.FONT_HERSHEY_SCREIPT_SIMPLEX:手寫(xiě)字體風(fēng)格
  • fontScale:字體的縮放因子
  • thickness:寬度大于0,標(biāo)識(shí)邊線寬度;小于0,畫(huà)實(shí)心矩形

實(shí)例:

font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(img,'OpenCV',(10,500), font, 4,(255,255,255),2,cv.LINE_AA) cv2.imshow('畫(huà)文字', img)

總結(jié)

以上是生活随笔為你收集整理的Python-OpenCV 笔记7 -- 绘图(Draw)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。