def shadow_image(self, img, pos):
if img is None:
return None
weighted_img = np.ones((img.shape[0], img.shape[1]), np.uint8)
x = int(pos.x() / self.scale)
y = int(pos.y() / self.scale)
weighted_img[y, x] = 0
dist_img = cv2.distanceTransform(weighted_img, distanceType=cv2.cv.CV_DIST_L2, maskSize=5).astype(np.float32)
dist_sigma = self.img_size/2.0
dist_img_f = np.exp(-dist_img / dist_sigma)
dist_img_f = np.tile(dist_img_f[..., np.newaxis], [1,1,3])
l = 0.25
img_f = img.astype(np.float32)
rst_f = (img_f * l + (1-l) * (img_f * dist_img_f + (1-dist_img_f)*255.0))
rst = rst_f.astype(np.uint8)
return rst
评论列表
文章目录