使用霍夫变换,我在目标上画圈,这是代码和结果
import cv2
import numpy as np
from matplotlib import pyplot as plt
import math
bgr_img = cv2.imread('16-Bit_ID-00001.jpg') # read as it is
if bgr_img.shape[-1] == 3: # color image
b,g,r = cv2.split(bgr_img) # get b,g,r
rgb_img = cv2.merge([r,g,b]) # switch it to rgb
gray_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2GRAY)
else:
gray_img = bgr_img
img = cv2.medianBlur(gray_img, 95) # blur value acts as a filter
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,30,
param1=50,param2=50,minRadius=60,maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
#sliceno = np.int32((math.pi + np.arctan2(Y, X)) * (N / (2 * math.pi)))
plt.subplot(121),plt.imshow(rgb_img)
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(cimg)
plt.title('Hough Transform'), plt.xticks([]), plt.yticks([])
plt.show()
现在我想把霍夫变换形成的圆分成12等份。有谁知道该怎么做?