Struck 跟踪算法(四)

       接下来分析Raw特征和Histogram特征。

       

       Raw特征:将图像缩放到16*16的像素空间内,各个像素值灰度化后为(0,1),结合高斯核函数,然后得到16*16=256维特征向量。

       实现源码如下:

  

/* 
 * Struck: Structured Output Tracking with Kernels
 * 
 * Code to accompany the paper:
 *   Struck: Structured Output Tracking with Kernels
 *   Sam Hare, Amir Saffari, Philip H. S. Torr
 *   International Conference on Computer Vision (ICCV), 2011
 * 
 * Copyright (C) 2011 Sam Hare, Oxford Brookes University, Oxford, UK
 * 
 * This file is part of Struck.
 * 
 * Struck is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Struck is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Struck.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

#include "RawFeatures.h"
#include "Config.h"
#include "Sample.h"
#include "Rect.h"

#include <iostream>

using namespace Eigen;
using namespace cv;

static const int kPatchSize = 16;

RawFeatures::RawFeatures(const Config& conf) :
	m_patchImage(kPatchSize, kPatchSize, CV_8UC1)
{
	SetCount(kPatchSize*kPatchSize);//设置维数大小
}

void RawFeatures::UpdateFeatureVector(const Sample& s)
{
	IntRect rect = s.GetROI(); // note this truncates to integers
	cv::Rect roi(rect.XMin(), rect.YMin(), rect.Width(), rect.Height());
	cv::resize(s.GetImage().GetImage(0)(roi), m_patchImage, m_patchImage.size());
	//equalizeHist(m_patchImage, m_patchImage);
	
	int ind = 0;
	for (int i = 0; i < kPatchSize; ++i)
	{
		uchar* pixel = m_patchImage.ptr(i);
		for (int j = 0; j < kPatchSize; ++j, ++pixel, ++ind)
		{
			m_featVec[ind] = ((double)*pixel)/255; //得到各个像素点的数值,存入m_featVec中。
		}
	}
}
 

        

         Histogram特征:将图像分为4层,第i层分为i*i个cell,每个cell计算其16个强度的直方统计分布向量,其特征维数为(1+4+9+16)*16=480维

/* 
 * Struck: Structured Output Tracking with Kernels
 * 
 * Code to accompany the paper:
 *   Struck: Structured Output Tracking with Kernels
 *   Sam Hare, Amir Saffari, Philip H. S. Torr
 *   International Conference on Computer Vision (ICCV), 2011
 * 
 * Copyright (C) 2011 Sam Hare, Oxford Brookes University, Oxford, UK
 * 
 * This file is part of Struck.
 * 
 * Struck is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Struck is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Struck.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

#include "HistogramFeatures.h"
#include "Config.h"
#include "Sample.h"
#include "Rect.h"

#include <iostream>

using namespace Eigen;
using namespace cv;
using namespace std;

static const int kNumBins = 16; //直方图  强度
static const int kNumLevels = 4;//层数
static const int kNumCellsX = 3;//cell个数
static const int kNumCellsY = 3;//cell个数

HistogramFeatures::HistogramFeatures(const Config& conf)
{
	int nc = 0;
	for (int i = 0; i < kNumLevels; ++i)
	{
		//nc += 1 << 2*i;
		nc += (i+1)*(i+1);
	}
	SetCount(kNumBins*nc);//设置特征维数大小  480维
	cout << "histogram bins: " << GetCount() << endl;
}

void HistogramFeatures::UpdateFeatureVector(const Sample& s)
{
	IntRect rect = s.GetROI(); // note this truncates to integers
	//cv::Rect roi(rect.XMin(), rect.YMin(), rect.Width(), rect.Height());
	//cv::resize(s.GetImage().GetImage(0)(roi), m_patchImage, m_patchImage.size());
	
	m_featVec.setZero();
	VectorXd hist(kNumBins);
	
	int histind = 0;
	for (int il = 0; il < kNumLevels; ++il)
	{
		//第il层划分cell个单元
		int nc = il+1;
		float w = s.GetROI().Width()/nc;
		float h = s.GetROI().Height()/nc;
		FloatRect cell(0.f, 0.f, w, h);

		//获取16个强度的直方图的分布图
		for (int iy = 0; iy < nc; ++iy)
		{
			cell.SetYMin(s.GetROI().YMin()+iy*h);
			for (int ix = 0; ix < nc; ++ix)
			{
				cell.SetXMin(s.GetROI().XMin()+ix*w);
				s.GetImage().Hist(cell, hist);
				m_featVec.segment(histind*kNumBins, kNumBins) = hist;
				++histind;
			}
		}
	}
	m_featVec /= histind;
}





评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值