def addEmoji(img,faces,emoji):
for x,y,w,h in faces:
# Resize emoji to desired width and height
dim = max(w,h)
em = cv.resize(emoji, (dim,dim), interpolation = cv.INTER_CUBIC)
# Get boolean for transparency
trans = em.copy()
trans[em == 0] = 1
trans[em != 0] = 0
# Delete all pixels in image where emoji is nonzero
img[y:y+h,x:x+w,:] *= trans
# Add emoji on those pixels
img[y:y+h,x:x+w,:] += em
return img
# Add emojis to image at specified points and sizes
# Inputs: img is ndarrays of WxHx3
# emojis is a list of WxHx3 emoji arrays
# faces is a list of (x,y,w,h) tuples for each face to be replaced
# Labels is a list of integer labels for each emotion
opencv_functions.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录