Struck 跟蹤演算法(二)

來源:互聯網
上載者:User

標籤:


下面開始讀具體源碼

config.h檔案

/*  * 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/>. *  */#ifndef CONFIG_H#define CONFIG_H#include <vector>#include <string>#include <ostream>#define VERBOSE (0)class Config{public:Config() { SetDefaults(); }Config(const std::string& path);//選擇提取特徵的方式  Haar特徵,Raw特徵,Histogram特徵enum FeatureType{kFeatureTypeHaar,kFeatureTypeRaw,kFeatureTypeHistogram};//SVM四種核函數enum KernelType{kKernelTypeLinear,kKernelTypeGaussian,kKernelTypeIntersection,kKernelTypeChi2};struct FeatureKernelPair{FeatureType feature;KernelType kernel;std::vector<double> params;};boolquietMode;booldebugMode;std::stringsequenceBasePath; //映像序列路徑std::stringsequenceName;//映像序列檔案夾名std::stringresultsPath; //結果路徑intframeWidth;//映像寬度intframeHeight;//映像高度intseed;intsearchRadius; //搜尋半徑doublesvmC;intsvmBudgetSize; //svm大小std::vector<FeatureKernelPair>features;friend std::ostream& operator<< (std::ostream& out, const Config& conf);private:void SetDefaults();static std::string FeatureName(FeatureType f);static std::string KernelName(KernelType k);};#endif


/*  * 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 "Config.h"#include <fstream>#include <iostream>#include <sstream>using namespace std;Config::Config(const std::string& path){SetDefaults();ifstream f(path.c_str());if (!f){cout << "error: could not load config file: " << path << endl;return;}string line, name, tmp;while (getline(f, line)){istringstream iss(line);iss >> name >> tmp;// skip invalid lines and commentsif (iss.fail() || tmp != "=" || name[0] == '#') continue;if      (name == "seed") iss >> seed;else if (name == "quietMode") iss >> quietMode;else if (name == "debugMode") iss >> debugMode;else if (name == "sequenceBasePath") iss >> sequenceBasePath;else if (name == "sequenceName") iss >> sequenceName;else if (name == "resultsPath") iss >> resultsPath;else if (name == "frameWidth") iss >> frameWidth;else if (name == "frameHeight") iss >> frameHeight;else if (name == "seed") iss >> seed;else if (name == "searchRadius") iss >> searchRadius;else if (name == "svmC") iss >> svmC;else if (name == "svmBudgetSize") iss >> svmBudgetSize;else if (name == "feature"){string featureName, kernelName;double param;iss >> featureName >> kernelName >> param;FeatureKernelPair fkp;if      (featureName == FeatureName(kFeatureTypeHaar)) fkp.feature = kFeatureTypeHaar;else if (featureName == FeatureName(kFeatureTypeRaw)) fkp.feature = kFeatureTypeRaw;else if (featureName == FeatureName(kFeatureTypeHistogram)) fkp.feature = kFeatureTypeHistogram;else{cout << "error: unrecognised feature: " << featureName << endl;continue;}if      (kernelName == KernelName(kKernelTypeLinear)) fkp.kernel = kKernelTypeLinear;else if (kernelName == KernelName(kKernelTypeIntersection)) fkp.kernel = kKernelTypeIntersection;else if (kernelName == KernelName(kKernelTypeChi2)) fkp.kernel = kKernelTypeChi2;else if (kernelName == KernelName(kKernelTypeGaussian)){if (iss.fail()){cout << "error: gaussian kernel requires a parameter (sigma)" << endl;continue;}fkp.kernel = kKernelTypeGaussian;fkp.params.push_back(param);}else{cout << "error: unrecognised kernel: " << kernelName << endl;continue;}features.push_back(fkp);}}}//預設參數設定void Config::SetDefaults(){quietMode = false;debugMode = false;sequenceBasePath = "";sequenceName = "";resultsPath = "";frameWidth = 320;frameHeight = 240;seed = 0;searchRadius = 30;svmC = 1.0;svmBudgetSize = 0;features.clear();}std::string Config::FeatureName(FeatureType f){switch (f){case kFeatureTypeRaw:return "raw";case kFeatureTypeHaar:return "haar";case kFeatureTypeHistogram:return "histogram";default:return "";}}std::string Config::KernelName(KernelType k){switch (k){case kKernelTypeLinear:return "linear";case kKernelTypeGaussian:return "gaussian";case kKernelTypeIntersection:return "intersection";case kKernelTypeChi2:return "chi2";default:return "";}}ostream& operator<< (ostream& out, const Config& conf){out << "config:" << endl;out << "  quietMode          = " << conf.quietMode << endl;out << "  debugMode          = " << conf.debugMode << endl;out << "  sequenceBasePath   = " << conf.sequenceBasePath << endl;out << "  sequenceName       = " << conf.sequenceName << endl;out << "  resultsPath        = " << conf.resultsPath << endl;out << "  frameWidth         = " << conf.frameWidth << endl;out << "  frameHeight        = " << conf.frameHeight << endl;out << "  seed               = " << conf.seed << endl;out << "  searchRadius       = " << conf.searchRadius << endl;out << "  svmC               = " << conf.svmC << endl;out << "  svmBudgetSize      = " << conf.svmBudgetSize << endl;for (int i = 0; i < (int)conf.features.size(); ++i){out << "  feature " << i << endl;out << "    feature: " << Config::FeatureName(conf.features[i].feature) << endl;out << "    kernel:  " << Config::KernelName(conf.features[i].kernel) <<endl;if (conf.features[i].params.size() > 0){out << "    params: ";for (int j = 0; j < (int)conf.features[i].params.size(); ++j){out << " " << conf.features[i].params[j];}out << endl;}}return out;}

以上是初始設定檔案源碼

後續、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

Struck 跟蹤演算法(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.