亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

opencv3/C++ 使用Tracker實(shí)現(xiàn)簡(jiǎn)單目標(biāo)跟蹤

 更新時(shí)間:2019年12月11日 09:17:04   作者:阿卡蒂奧  
今天小編就為大家分享一篇opencv3/C++ 使用Tracker實(shí)現(xiàn)簡(jiǎn)單目標(biāo)跟蹤,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

簡(jiǎn)介

MIL: TrackerMIL 以在線(xiàn)方式訓(xùn)練分類(lèi)器將對(duì)象與背景分離;多實(shí)例學(xué)習(xí)避免魯棒跟蹤的漂移問(wèn)題.

OLB: TrackerBoosting 基于AdaBoost算法的在線(xiàn)實(shí)時(shí)對(duì)象跟蹤.分類(lèi)器在更新步驟中使用周?chē)尘白鳛榉蠢员苊馄茊?wèn)題.

MedianFlow: TrackerMedianFlow 跟蹤器適用于非常平滑和可預(yù)測(cè)的運(yùn)動(dòng),物體在整個(gè)序列中可見(jiàn).

TLD: TrackerTLD 將長(zhǎng)期跟蹤任務(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)周?chē)鷧^(qū)域的循環(huán)矩陣采集正負(fù)樣本,利用脊回歸訓(xùn)練目標(biāo)檢測(cè)器,并成功的利用循環(huán)矩陣在傅里葉空間可對(duì)角化的性質(zhì)將矩陣的運(yùn)算轉(zhuǎn)化為向量的Hadamad積,即元素的點(diǎn)乘,大大降低了運(yùn)算量,提高了運(yùn)算速度,使算法滿(mǎn)足實(shí)時(shí)性要求.

部分相關(guān)API:

TrackerMIL

 static Ptr<TrackerMIL> create(const TrackerMIL::Params &parameters);
 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 &parameters);
 CV_WRAP static Ptr<TrackerBoosting> create();
 struct CV_EXPORTS Params
{
 PARAMS();
  int numClassifiers; //在OnlineBoosting算法中使用的分類(lèi)器的數(shù)量
  float samplerOverlap; //搜索區(qū)域參數(shù)
  float samplerSearchFactor; //搜索區(qū)域參數(shù)
  int iterationInit; //初始迭代
  int featureSetNumFeatures; //特征
 //從文件讀取參數(shù)
  void read(const FileNode&fn);
 //從文件寫(xiě)入?yún)?shù)
  void write(FileStorage&fs)const;
 };

示例

首先獲取視頻的第一幀,通過(guò)點(diǎn)擊左鍵框選選擇要跟蹤的目標(biāo),點(diǎn)擊右鍵確認(rèn)并使用MIL開(kāi)始跟蹤.(從實(shí)際情況看來(lái),算法對(duì)過(guò)程中有遮擋的情況跟蹤能力較差.)

(環(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ì)于無(wú)遮擋情況跟蹤效果較好;TLD對(duì)部分遮擋處理的效果最好,處理時(shí)間相對(duì)較慢.

部分遮擋處理效果

MIL對(duì)部分遮擋的處理效果:

opencv::Tracker Algorithms

以上這篇opencv3/C++ 使用Tracker實(shí)現(xiàn)簡(jiǎn)單目標(biāo)跟蹤就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論