opencv 3/C++Tracker 를 사용 하여 간단 한 목표 추적 을 실현 합 니 다.

간단 한 소개
MIL:TrackerMIL 은 분류 기 를 온라인 으로 훈련 시 켜 대상 과 배경 을 분리 합 니 다.다 중 인 스 턴 스 학습 은 로 봉 이 추적 하 는 이동 문 제 를 피한다.
OLB:TrackerBoosting 은 AdaBoost 알고리즘 을 기반 으로 한 온라인 실시 간 대상 추적 입 니 다.분류 기 는 업데이트 단계 에서 주변 배경 을 반 례 로 사용 하여 표류 문 제 를 피 합 니 다.
MedianFlow:Tracker MedianFlow 추적 기 는 매우 부 드 럽 고 예측 가능 한 운동 에 적용 되 며 물 체 는 전체 서열 에서 볼 수 있 습 니 다.
TLD:TrackerTLD 는 장기 추적 임 무 를 추적,학습,검 측 으로 분해 합 니 다.추적 기 는 프레임 간 추적 대상 입 니 다.탐측 기 는 현지 화 되 어 관찰 한 모든 외관 을 관찰 하고 필요 할 때 추적 기 를 바로 잡 습 니 다.예측 검출 기의 오 류 를 배우 고 업데이트 하여 더 이상 이러한 오류 가 발생 하지 않도록 합 니 다.추적 기 는 빠 른 운동,일부 차단,물체 부족 등 을 처리 할 수 있 습 니 다.
KCF:TrackerKCF 는 목표 주변 지역 의 순환 행렬 을 이용 하여 양음 샘플 을 수집 하고 척 추 를 이용 하여 목표 검출 기 를 훈련 시 키 며 순환 행렬 을 성공 적 으로 이용 하여 푸 리 엽 공간 에서 각 화 된 성질 로 행렬 의 연산 을 벡터 의 Hadamad 적,즉 요소 의 점 승 으로 전환 시 켜 연산 량 을 크게 낮 추고 연산 속 도 를 높 여 알고리즘 이 실시 간 요 구 를 만족 시 켰 다.
부분 관련 API:
TrackerMIL

 static Ptr<TrackerMIL> create(const TrackerMIL::Params &parameters);
 CV_WRAP static Ptr<TrackerMIL> create();

struct CV_EXPORTS Params
 {
 PARAMS();
  //      
  float samplerInitInRadius; //           
  int samplerInitMaxNegNum; //       
  float samplerSearchWinSize; //       
  float samplerTrackInRadius; //              
  int samplerTrackMaxPosNum; //           
  int samplerTrackMaxNegNum; //           
  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            
  float samplerOverlap; //      
  float samplerSearchFactor; //      
  int iterationInit; //    
  int featureSetNumFeatures; //  
 //       
  void read(const FileNode&fn);
 //       
  void write(FileStorage&fs)const;
 };
예시
먼저 영상의 첫 번 째 프레임 을 가 져 옵 니 다.왼쪽 단 추 를 누 르 면 추적 할 목 표를 선택 하고 오른쪽 단 추 를 누 르 면 확인 하고 MIL 을 사용 하여 추적 을 시작 합 니 다.(실제 상황 에서 볼 때 알고리즘 은 과정 에서 가 려 진 상황 에 대한 추적 능력 이 떨 어 집 니 다.)
(환경:Ubuntu 16.04+QT 5.8+opencv 3.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 ...
"); return -1; } // , 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; } // 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"); } }



실험 비교 결과 에 따 르 면 KCF 속도 가 가장 빠 르 고 MedianFlow 의 속도 도 비교적 빠 르 며 가 려 지지 않 은 상황 에 대한 추적 효과 가 비교적 좋다.TLD 는 부분 차단 처리 효과 가 가장 좋 고 처리 시간 이 상대 적 으로 느리다.
부분 차단 처리 효과
MIL 부분 가리기 처리 효과:


opencv::Tracker Algorithms
이상 의 opencv 3/C++는 Tracker 를 사용 하여 간단 한 목표 추적 을 실현 하 는 것 이 바로 편집장 이 여러분 에 게 공유 하 는 모든 내용 입 니 다.여러분 께 참고 가 되 고 저 희 를 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기