iT邦幫忙

2022 iThome 鐵人賽

0
自我挑戰組

大四要畢業了但還不太會python合理嗎系列 第 24

Day24 - 國寶圓圓昨天鼠掉了......

  • 分享至 

  • xImage
  •  

https://ithelp.ithome.com.tw/upload/images/20221121/20151839tCdfmu76j1.jpg

import cv2

# 載入並顯示圖片
img = cv2.imread('test.jpg')
cv2.imshow('img', img)
# 灰度化
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 輸出圖像大小,方便根據圖像大小調節minRadius和maxRadius
print(img.shape)
# 霍夫變換圓檢測
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1,
                           100, param1=100, param2=30, minRadius=5, maxRadius=300)
# 輸出返回值,方便查看類型
print(circles)
print(circles[0])
# 輸出檢測到圓的個數
print(len(circles[0]))

print('------------------------------')
# 根據檢測到圓的信息,畫出每一個圓
for circle in circles[0]:
    # 圓的基本信息
    print(circle[2])
    # 座標行列
    x = int(circle[0])
    y = int(circle[1])
    # 半徑
    r = int(circle[2])
    # 在原圖用指定顏色標記出圓的位置
    img = cv2.circle(img, (x, y), r, (0, 0, 255), 3)
    img = cv2.circle(img, (x, y), 2, (255, 255, 0), -1)
# 顯示新圖像
cv2.imshow('res', img)

# 按任意鍵退出
cv2.waitKey(0)
cv2.destroyAllWindows()

https://ithelp.ithome.com.tw/upload/images/20221121/20151839PVFEuaZuJV.jpg

https://ithelp.ithome.com.tw/upload/images/20221121/20151839GNQyZAi4DZ.jpg


上一篇
Day-23 圓環的形成
下一篇
Day25- Sponge Blob?
系列文
大四要畢業了但還不太會python合理嗎30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
CCCCC
iT邦新手 4 級 ‧ 2022-11-24 13:49:15

是團團

我要留言

立即登入留言