看了篇关于人体特征点热力图绘制的方法,
https://blog.csdn.net/zziahgf/article/details/79704788
然后尝试用opencv的draw加上scipy的高斯模糊,发现结果是几乎和上面链接说的是一样的. (仅适用于原图相对较大的情况下)
用opencv的draw line或者circle(或者直接设置坐标处,值为1. 这样更快), 设置半径为1,填充模式即可
在这里只是想说明:
1.用cv2.line可以更快画出点与点之间的高斯分布模型.
2.支持一图层有多个高斯分布
3.某些模型下需要多点,多线的高斯分布. 从头开始写的话几乎好难有完美的解决方法
def json2point(input_shape, c_x, c_y, sigma):
img_height = input_shape[0]
img_width = input_shape[1]
X1 = np.linspace(1, img_width, img_width)
Y1 = np.linspace(1, img_height, img_height)
[X, Y] = np.meshgrid(X1, Y1)
X = X - c_x
Y = Y - c_y
D2 = X * X + Y * Y
E2 = 2.0 * sigma * sigma
Exponent = D2 / E2
heatmap = np.exp(-Exponent)
return heatmap
h = 265
w = 320
cx = int(w/2)
cy = int(h/2)
heatmap = json2heatmap([h, w], cx, cy, 25)
from scipy.ndimage import gaussian_filter
import cv2
b = np.zeros((h, w))
cv2.circle(b, (cx, cy), 15 , 1, cv2.FILLED)
# b[cx,cy]=1 这样会快点,原理差不多
b = gaussian_filter(b, 25)
maxi = np.amax(b) # 模糊之后最大值不为1
b = b * 1/maxi
c = np.zeros((h,w))
cv2.line(c, (cx-100,cy-100),(cx+100,cy+100),1,1)
c = gaussian_filter(c, 25)
maxi = np.amax(c)
c = c * 1/maxi
plt.subplot(1,3,1)
plt.imshow(heatmap)
plt.subplot(1,3,2)
plt.imshow(b)
plt.subplot(1,3,3)
plt.imshow(c)
plt.show()