我正在尝试掩盖图像中的圆形区域。我将代码和输出图像放在下面。如您所见,我在虹膜周围画了一个圆圈。在此之后,我想将圆形区域之外的所有内容涂黑。我需要什么继续?还有其他方法吗?
谢谢...
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('i1.jpg',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,120,
param1=50,param2=50,minRadius=30,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)
cv2.imwrite("iris.jpg",cimg)
plt.imshow(cimg, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()