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 ¶meters);
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 ¶meters);
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 를 사용 하여 간단 한 목표 추적 을 실현 하 는 것 이 바로 편집장 이 여러분 에 게 공유 하 는 모든 내용 입 니 다.여러분 께 참고 가 되 고 저 희 를 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Visual Studio에서 파일 폴더 구분 (포함 경로 설정)Visual Studio에서 c, cpp, h, hpp 파일을 폴더로 나누고 싶었습니까? 어쩌면 대부분의 사람들이 있다고 생각합니다. 처음에 파일이 만들어지는 장소는 프로젝트 파일 등과 같은 장소에 있기 때문에 파일...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.