我正在使用来自这里的想法来实现用于对象跟踪的 MeanShift 算法:http ://www.cse.psu.edu/~rtc12/CSE598C/meanShiftColor.pdf
现在我有后续帧的反投影图像。此类图像中的每个像素都标记了属于被跟踪对象的概率:
w(x i ) = 反投影图像中的像素。
x = 当前中心像素。
我不明白是什么spatial kernel
。
假设它可以是大小为 5x5 的 2D 高斯核,则 K(x i -x)*w(x i ) 可以用预模糊图像的像素代替。
我的代码看起来是这样的:
fvect2 findMeanShift(const PlainImage<uint8>& weights_smoothed, fvect2 old_center, DebugOutput& debug)
{
//LOGE("first center: %.2f %.2f", old_center.x, old_center.y);
const int w=weights_smoothed.getWidth(), h=weights_smoothed.getHeight();
int iter_count = 0;
fvect2 total_shift(0.0,0.0);
while(iter_count++ < 20)
{
fvect2 fTop(0,0);
float fBottom=0.0;
for(int y=0;y<h;++y)
for(int x=0;x<w;++x)
{
fvect2 cur_center(x, y);
float mult = weights_smoothed.at(x, y)[0]/255.0;
fBottom += mult;
fTop += (cur_center-old_center) * mult;
}
fvect2 mean_shift = fTop/fBottom;
//printf("mean_shift: %.2f %.2f", mean_shift.x, mean_shift.y);
debug.addArrow(old_center, old_center+mean_shift);
old_center += mean_shift;
//printf("old_center: %.2f %.2f", old_center.x, old_center.y);
total_shift += mean_shift;
if(mean_shift.lengthF()<0.1)
break;
}
return total_shift;
}
所以我只是通过平滑的反投影图像进行迭代,并且对于每个像素:
将其值添加到分母,
将其值乘以从当前中心到分母的偏移。
它在第二次迭代时收敛,但 shift 是错误的,我不知道如何调试它。可能是公式实现中的问题。
请用人类语言向我解释什么是空间内核以及如何将其应用于权重图像。谢谢!