基于KCF算法的opencv3目标跟踪

std::string video = argv[1];
VideoCapture cap(video);
在官方给出的单目标跟踪示例中,我运行之后只能出来最开始的帮助里的提示,没有跟踪的视频显示,这段代码到底是怎么提取视频的呢?
附上源码:
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main( int argc, char** argv ){
// show help
if(argc cout " Usage: tracker \n"
" examples:\n"
" example_tracking_kcf Bolt/img/%04d.jpg\n"
" example_tracking_kcf faceocc2.webm\n"
<< endl;
return 0;
}
// declares all required variables
Rect2d roi;
Mat frame;
// create a tracker object KCF MIL TLD
Ptr tracker = TrackerKCF::create();
// set input video
std::string video = argv[1];
VideoCapture cap(video);
// get bounding box
cap >> frame;
int sale = 2;
resize(frame,frame,frame.size()/2);
roi=selectROI("tracker",frame);
//quit if ROI was not selected
if(roi.width==0 || roi.height==0)
return 0;
// initialize the tracker
tracker->init(frame,roi);
// perform the tracking process
printf("Start the tracking process, press ESC to quit.\n");
for ( ;; ){
// get frame from the video
cap >> frame;
// stop the program if no more images
if(frame.rows==0 || frame.cols==0)
break;
resize(frame,frame,frame.size()/2);
// update the tracking result
tracker->update(frame,roi);
// draw the tracked object
rectangle( frame, roi, Scalar( 255, 0, 0 ), 2, 1 );
// show image with the tracked object
imshow("tracker",frame);
//quit on ESC button
if(waitKey(1)==27)break;
}
return 0;
}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问