【发布时间】:2015-12-15 13:41:11
【问题描述】:
我正在尝试掩盖图像中的圆形区域。我将代码和输出图像放在下面。如您所见,我在虹膜周围画了一个圆圈。在此之后,我想将圆形区域之外的所有内容都涂黑。如何我需要继续吗?还有其他方法吗?
谢谢...
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()
【问题讨论】:
-
创建与原始图像大小相同的黑色图像。用
cv2.circle函数在你想要你的面具的地方画一个实心的白色圆圈。使用带有反向掩码或掩码的 .setTo 或 .copyTo 函数,如果这些函数存在于 python opencv 中。
标签: python opencv iris-recognition