MOSSE算法源码简单解析
源码
如下:
// This file ispart of the OpenCV project.
// It is subject to the license terms in the LICENSEfile found in the top-level directory
// of this distribution and athttp://opencv.org/license.html.
//
//[1] David S. Bolme et al. "Visual Object Trackingusing Adaptive Correlation Filters"
// http://www.cs.colostate.edu/~draper/papers/bolme_cvpr10.pdf
//
//
// credits:
// Kun-Hsin Chen: for initial c++ code
// Cracki: for the idea of only converting the usedpatch to gray
//
#include "opencv2/tracking.hpp"
namespace cv {
namespace tracking {
struct DummyModel :TrackerModel
{
virtual void modelUpdateImpl(){}
virtual void modelEstimationImpl( const std::vector<Mat>& ){}
};
const double eps=0.00001; // fornormalization
const double rate=0.2; //learning rate
const double psrThreshold=5.7; //no detection, if PSR is smaller than this
struct MosseImpl :TrackerMOSSE
{
protected:
Point2d center;//center of the bounding box
Size size; //size ofthe bounding box
Mat hanWin;
Mat G; //goal
Mat H, A,B; //state
// Element-wisedivision of complex numbers in src1 and src2
Mat divDFTs( const Mat &src1, const Mat &src2 ) const
{
Mat c1[2],c2[2],a1,a2,s1,s2,denom,re,im;
// split into re and im per src
cv::split(src1, c1);
cv::split(src2, c2);
// (Re2*Re2 + Im2*Im2) = denom
// denom is same forboth channels
cv::multiply(c2[0], c2[0], s1);
cv::multiply(c2[1], c2[1], s2);
cv::add(s1,s2, denom);
// (Re1*Re2 + Im1*Im1)/(Re2*Re2 + Im2*Im2) = Re
cv::multiply(c1[0], c2[0], a1);
cv::multiply(c1[1], c2[1], a2);
cv::divide(a1+