我认为您也可以为此使用直方图反投影。在那里,您也可以使用任意形状的蒙版。将遮罩与反投影图像进行卷积,您将在图像中出现对象的区域检测到一个峰值,如下图(颜色映射和缩放)所示。
反投影:
卷积:
编辑:
这是基于此paper。我正在试验它,并希望在博客中发布。
这是用 C++ 编写的。
// model histogram: this is the football template
calcHist(&model32fc3, 1, (const int*)channels, modelMask, histModel, 3, (const int*)histSize, (const float**)ranges, true, false);
// image histogram
calcHist(&image32fc3, 1, (const int*)channels, Mat(), histImage, 3, (const int*)histSize, (const float**)ranges, true, false);
// ratio histogram
divide(histModel, histImage, histRatio);
cv::min(histRatio, 1.0, histRatio);
// backproject ratio histogram
calcBackProject(&image32fc3, 1, (const int*)channels, histRatio, backprj, (const float**)ranges);
// convolve the kernel with the backprojected image
filter2D(backprj, conv, CV_32F, modelMask);