码迷,mamicode.com
首页 > 其他好文 > 详细

Struck 跟踪算法(四)

时间:2014-07-27 23:50:49      阅读:512      评论:0      收藏:0      [点我收藏+]

标签:http   os   io   for   art   ar   算法   amp   

       接下来分析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;
}





Struck 跟踪算法(四),布布扣,bubuko.com

Struck 跟踪算法(四)

标签:http   os   io   for   art   ar   算法   amp   

原文地址:http://blog.csdn.net/sunboyiris/article/details/38179267

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!