opencv 3.2 中的KCF 跟踪算法 如何判断目标跟丢????

大大的道道的 2017-12-11 04:58:51
如下代码中的isFound 一直为true, 并不能判断是否跟丢



/*----------------------------------------------
* Usage:
* example_tracking_kcf <video_name>
*
* example:
* example_tracking_kcf Bolt/img/%04.jpg
* example_tracking_kcf faceocc2.webm
*--------------------------------------------------*/

#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>
#include "samples_utility.hpp"

using namespace std;
using namespace cv;

int main( int argc, char** argv ){
// show help
if(argc<2){
cout<<
" Usage: example_tracking_kcf <video_name>\n"
" examples:\n"
" example_tracking_kcf Bolt/img/%04.jpg\n"
" example_tracking_kcf faceocc2.webm\n"
<< endl;
return 0;
}

// create the tracker
Ptr<Tracker> tracker = TrackerKCF::create();

// set input video
std::string video = argv[1];
VideoCapture cap(video);

Mat frame;

// get bounding box
cap >> frame;
Rect2d roi= selectROI("tracker", frame, true, false);

//quit if ROI was not selected
if(roi.width==0 || roi.height==0)
return 0;

// initialize the tracker
tracker->init(frame,roi);

// do the tracking
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;

// update the tracking result
bool isfound = tracker->update(frame,roi);
if(!isfound)
{
cout << "The target has been lost...\n";
waitKey(0);
return 0;
}

// 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;
}

}
...全文
3919 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
大大的道道的 2018-07-09
  • 打赏
  • 举报
回复
@qq_22823553 好早就解决了

Params 是public 的变量啊 为啥不能更改??

赵4老师 2018-04-28
  • 打赏
  • 举报
回复
VS IDE中,在不明白的符号上点鼠标右键,选转到定义或查找所有引用。
js8878 2018-04-27
  • 打赏
  • 举报
回复
引用 4 楼 u011258240 的回复:
@wwzh2003
这个函数无法在主程序里引用!
大大的道道的 2018-01-02
  • 打赏
  • 举报
回复

@wwzh2003
js8878 2017-12-25
  • 打赏
  • 举报
回复
楼上的请问params:: thresh在哪里呀
大大的道道的 2017-12-15
  • 打赏
  • 举报
回复
opencv 3.3 中有个 params:: thresh 可以设置阈值0-1 之间, 用这个判断是否跟丢
赵4老师 2017-12-11
  • 打赏
  • 举报
回复
提醒:OpenCV是开源的。

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧