| 
 | 
 
 
| 
原圖
 Python cv2 霍夫轉換 圓形偵測 
 
 
 
 
 
完整代碼 
- import numpy as np
 
 - import cv2, os
 
 - img1 = cv2.imread('coins.png')
 
 - img2 = img1.copy()
 
 - gray = cv2.cvtColor(img1 , cv2.COLOR_RGB2GRAY)
 
 - circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT,1,50,20,10,minRadius=50,maxRadius=80)
 
  
- #print(circles)
 
 - circles = np.uint16(np.around(circles))
 
 - #print(circles)
 
 - for i in circles[0,:]:
 
 -     print('i:',i)
 
 -     cv2.circle(img2, (i[0], i[1]), i[2], (0,255,0), 10) #畫圓
 
 -     cv2.circle(img2, (i[0], i[1]), 2, (0, 0, 255), 3)#畫圓心
 
 - cv2.imshow('img1',img1)
 
 - # cv2.imshow('gray',gray)
 
 - # cv2.imshow('circles',circles)
 
 - cv2.imwrite('HoughCircles.png', img2)
 
 - cv2.imshow('img2',img2)
 
 - cv2.waitKey()
 
  複製代碼 
 
 
 
 
 
結果圖 
 
Python cv2 霍夫轉換 圓形偵測 
 
 
 
 
文章出處:網頁設計,網站架設 ,網路行銷,網頁優化,SEO - NetYea 網頁設計 
 |   
 
 
 
 |