def skin_filter(cfg, vd):
df = pd.read_csv(vd.photo_csv, index_col=0)
numbers = df.number.tolist()
notface = []
for number in numbers:
lower = np.array([0, 48, 80], dtype = "uint8")
upper = np.array([13, 255, 255], dtype = "uint8")
image = cv2.imread('%s/%d.png' % (vd.photo_dir, number), cv2.IMREAD_COLOR)
converted = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
skinMask = cv2.inRange(converted, lower, upper)
# apply a series of erosions and dilations to the mask
# using an elliptical kernel
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11, 11))
skinMask = cv2.erode(skinMask, kernel, iterations = 2)
skinMask = cv2.dilate(skinMask, kernel, iterations = 2)
# blur the mask to help remove noise, then apply the
# mask to the frame
skinMask = cv2.GaussianBlur(skinMask, (3, 3), 0)
skin = cv2.bitwise_and(image, image, mask = skinMask)
if len(skin.nonzero()[0]) < cfg.min_skin_pixels:
notface.append(number)
print '%d/%d are faces' % ( len(df) - len(notface), len(df) )
df['face']= 1
df.loc[df.number.isin(notface),'face'] = -99
df.to_csv(vd.photo_csv)
评论列表
文章目录