這篇文章主要介紹了opencv3/C++如何使用Tracker實(shí)現(xiàn)目標(biāo)跟蹤,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
簡介
MIL: TrackerMIL 以在線方式訓(xùn)練分類器將對(duì)象與背景分離;多實(shí)例學(xué)習(xí)避免魯棒跟蹤的漂移問題.
OLB: TrackerBoosting 基于AdaBoost算法的在線實(shí)時(shí)對(duì)象跟蹤.分類器在更新步驟中使用周圍背景作為反例以避免漂移問題.
MedianFlow: TrackerMedianFlow 跟蹤器適用于非常平滑和可預(yù)測(cè)的運(yùn)動(dòng),物體在整個(gè)序列中可見.
TLD: TrackerTLD 將長期跟蹤任務(wù)分解為跟蹤,學(xué)習(xí)和檢測(cè).跟蹤器在幀之間跟蹤對(duì)象.探測(cè)器本地化所觀察到的所有外觀,并在必要時(shí)糾正跟蹤器.學(xué)習(xí)估計(jì)檢測(cè)器的錯(cuò)誤并進(jìn)行更新以避免再出現(xiàn)這些錯(cuò)誤.追蹤器能夠處理快速運(yùn)動(dòng),部分遮擋,物體缺失等情況.
KCF: TrackerKCF 使用目標(biāo)周圍區(qū)域的循環(huán)矩陣采集正負(fù)樣本,利用脊回歸訓(xùn)練目標(biāo)檢測(cè)器,并成功的利用循環(huán)矩陣在傅里葉空間可對(duì)角化的性質(zhì)將矩陣的運(yùn)算轉(zhuǎn)化為向量的Hadamad積,即元素的點(diǎn)乘,大大降低了運(yùn)算量,提高了運(yùn)算速度,使算法滿足實(shí)時(shí)性要求.
部分相關(guān)API:
TrackerMIL
static Ptr<TrackerMIL> create(const TrackerMIL::Params ¶meters); CV_WRAP static Ptr<TrackerMIL> create();
struct CV_EXPORTS Params { PARAMS(); //采樣器的參數(shù) float samplerInitInRadius; //初始收集正面實(shí)例的半徑 int samplerInitMaxNegNum; //初始使用負(fù)樣本 float samplerSearchWinSize; //搜索窗口的大小 float samplerTrackInRadius; //在跟蹤期間收集正面實(shí)例的半徑 int samplerTrackMaxPosNum; //在追蹤期間使用正面樣本 int samplerTrackMaxNegNum; //在跟蹤期間使用的負(fù)樣本 int featureSetNumFeatures; //特征 void read(const FileNode&fn); void write(FileStorage&fs)const; };
TrackerBoosting
static Ptr<TrackerBoosting> create(const TrackerBoosting::Params ¶meters); CV_WRAP static Ptr<TrackerBoosting> create();
struct CV_EXPORTS Params{ PARAMS(); int numClassifiers; //在OnlineBoosting算法中使用的分類器的數(shù)量 float samplerOverlap; //搜索區(qū)域參數(shù) float samplerSearchFactor; //搜索區(qū)域參數(shù) int iterationInit; //初始迭代 int featureSetNumFeatures; //特征 //從文件讀取參數(shù) void read(const FileNode&fn); //從文件寫入?yún)?shù) void write(FileStorage&fs)const; };
示例
首先獲取視頻的第一幀,通過點(diǎn)擊左鍵框選選擇要跟蹤的目標(biāo),點(diǎn)擊右鍵確認(rèn)并使用MIL開始跟蹤.(從實(shí)際情況看來,算法對(duì)過程中有遮擋的情況跟蹤能力較差.)
(環(huán)境:Ubuntu16.04+QT5.8+opencv3.3.1)
#include <opencv2/opencv.hpp>#include <opencv2/video.hpp>#include <opencv2/tracking.hpp>#include <opencv2/tracking/tracker.hpp>using namespace cv;void draw_rectangle(int event, int x, int y, int flags, void*);Mat firstFrame;Point previousPoint, currentPoint;Rect2d bbox;int main(int argc, char *argv[]){ VideoCapture capture; Mat frame; frame = capture.open("/home/w/mycode/QT/img/runners.avi"); if(!capture.isOpened()) { printf("can not open ...\n"); return -1; } //獲取視頻的第一幀,并框選目標(biāo) capture.read(firstFrame); if(!firstFrame.empty()) { namedWindow("output", WINDOW_AUTOSIZE); imshow("output", firstFrame); setMouseCallback("output", draw_rectangle, 0); waitKey(); } //使用TrackerMIL跟蹤 Ptr<TrackerMIL> tracker= TrackerMIL::create(); //Ptr<TrackerTLD> tracker= TrackerTLD::create(); //Ptr<TrackerKCF> tracker = TrackerKCF::create(); //Ptr<TrackerMedianFlow> tracker = TrackerMedianFlow::create(); //Ptr<TrackerBoosting> tracker= TrackerBoosting::create(); capture.read(frame); tracker->init(frame,bbox); namedWindow("output", WINDOW_AUTOSIZE); while (capture.read(frame)) { tracker->update(frame,bbox); rectangle(frame,bbox, Scalar(255, 0, 0), 2, 1); imshow("output", frame); if(waitKey(20)=='q') return 0; } capture.release(); destroyWindow("output"); return 0;}//框選目標(biāo)void draw_rectangle(int event, int x, int y, int flags, void*){ if (event == EVENT_LBUTTONDOWN) { previousPoint = Point(x, y); } else if (event == EVENT_MOUSEMOVE && (flags&EVENT_FLAG_LBUTTON)) { Mat tmp; firstFrame.copyTo(tmp); currentPoint = Point(x, y); rectangle(tmp, previousPoint, currentPoint, Scalar(0, 255, 0, 0), 1, 8, 0); imshow("output", tmp); } else if (event == EVENT_LBUTTONUP) { bbox.x = previousPoint.x; bbox.y = previousPoint.y; bbox.width = abs(previousPoint.x-currentPoint.x); bbox.height = abs(previousPoint.y-currentPoint.y); } else if (event == EVENT_RBUTTONUP) { destroyWindow("output"); }}
實(shí)驗(yàn)對(duì)比發(fā)現(xiàn):KCF速度最快,MedianFlow的速度也較快,對(duì)于無遮擋情況跟蹤效果較好;TLD對(duì)部分遮擋處理的效果好,處理時(shí)間相對(duì)較慢.
部分遮擋處理效果
MIL對(duì)部分遮擋的處理效果:
opencv::Tracker Algorithms
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“opencv3/C++如何使用Tracker實(shí)現(xiàn)目標(biāo)跟蹤”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
分享名稱:opencv3/C++如何使用Tracker實(shí)現(xiàn)目標(biāo)跟蹤-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://sd-ha.com/article22/cdesjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、品牌網(wǎng)站建設(shè)、域名注冊(cè)、用戶體驗(yàn)、網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容