这个KCF跟踪算法如何运行?

js8878 2016-01-03 03:23:38
我用VS2010+opencv2.4.11编译成功了,但是如何把read images那部分改成自己图片集的路径啊?我改了listFramesFile.open(listFrames);只是把红字部分改成自己图片路径,结果一点release,控制台就一闪而过,不知道怎么解决啊?
KCF跟踪我下了一堆,就这一个可以编译成功的,但跑不起来啊


源码如下:
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include "kcftracker.hpp"

#include <dirent.h>

using namespace std;
using namespace cv;

int main(int argc, char* argv[]){

if (argc > 5) return -1;

bool HOG = true;
bool FIXEDWINDOW = false;
bool MULTISCALE = true;
bool SILENT = true;
bool LAB = false;

for(int i = 0; i < argc; i++){
if ( strcmp (argv[i], "hog") == 0 )
HOG = true;
if ( strcmp (argv[i], "fixed_window") == 0 )
FIXEDWINDOW = true;
if ( strcmp (argv[i], "singlescale") == 0 )
MULTISCALE = false;
if ( strcmp (argv[i], "show") == 0 )
SILENT = false;
if ( strcmp (argv[i], "lab") == 0 ){
LAB = true;
HOG = true;
}
if ( strcmp (argv[i], "gray") == 0 )
HOG = false;
}

// Create KCFTracker object
KCFTracker tracker(HOG, FIXEDWINDOW, MULTISCALE, LAB);

// Frame readed
Mat frame;

// Tracker results
Rect result;

// Path to list.txt
ifstream listFile;
string fileName = "images.txt";
listFile.open(fileName);

// Read groundtruth for the 1st frame
ifstream groundtruthFile;
string groundtruth = "region.txt";
groundtruthFile.open(groundtruth);
string firstLine;
getline(groundtruthFile, firstLine);
groundtruthFile.close();

istringstream ss(firstLine);

// Read groundtruth like a dumb
float x1, y1, x2, y2, x3, y3, x4, y4;
char ch;
ss >> x1;
ss >> ch;
ss >> y1;
ss >> ch;
ss >> x2;
ss >> ch;
ss >> y2;
ss >> ch;
ss >> x3;
ss >> ch;
ss >> y3;
ss >> ch;
ss >> x4;
ss >> ch;
ss >> y4;

// Using min and max of X and Y for groundtruth rectangle
float xMin = min(x1, min(x2, min(x3, x4)));
float yMin = min(y1, min(y2, min(y3, y4)));
float width = max(x1, max(x2, max(x3, x4))) - xMin;
float height = max(y1, max(y2, max(y3, y4))) - yMin;


// Read Images
ifstream listFramesFile;
string listFrames = "images.txt";
listFramesFile.open(listFrames);
string frameName;


// Write Results
ofstream resultsFile;
string resultsPath = "output.txt";
resultsFile.open(resultsPath);

// Frame counter
int nFrames = 0;


while ( getline(listFramesFile, frameName) ){
frameName = frameName;

// Read each frame from the list
frame = imread(frameName, CV_LOAD_IMAGE_COLOR);

// First frame, give the groundtruth to the tracker
if (nFrames == 0) {
tracker.init( Rect(xMin, yMin, width, height), frame );
rectangle( frame, Point( xMin, yMin ), Point( xMin+width, yMin+height), Scalar( 0, 255, 255 ), 1, 8 );
resultsFile << xMin << "," << yMin << "," << width << "," << height << endl;
}
// Update
else{
result = tracker.update(frame);
rectangle( frame, Point( result.x, result.y ), Point( result.x+result.width, result.y+result.height), Scalar( 0, 255, 255 ), 1, 8 );
resultsFile << result.x << "," << result.y << "," << result.width << "," << result.height << endl;
}

nFrames++;

if (!SILENT){
imshow("Image", frame);
waitKey(1);
}
}
resultsFile.close();

listFile.close();

}



我另外还下了其他版本的KCF,要cmake的,但cmake编译都不成功

是不是要求得结合opencv3.0?

这是cmakelists的内容:
cmake_minimum_required(VERSION 2.8)
project(test)

find_package(OpenCV REQUIRED)

if(NOT WIN32)
ADD_DEFINITIONS("-std=c++0x -O3")
endif(NOT WIN32)

include_directories(src)
FILE(GLOB_RECURSE sourcefiles "src/*.cpp")
add_executable( KCF ${sourcefiles} )
target_link_libraries( KCF ${OpenCV_LIBS})

Compilation instructions

There are no external dependencies other than OpenCV 3.0.0. Tested on a freshly installed Ubuntu 14.04.

1) cmake CMakeLists.txt
2) make

该怎么编译呢?
...全文
10422 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_36832169 2017-11-23
  • 打赏
  • 举报
回复
楼主我在opencv320+vs2015运行你给的代码出现错误怎么解决?跪求指点 严重性 代码 说明 项目 文件 行 错误 C1083 无法打开包括文件: “kcftracker.hpp”: No such file or directory kcf6 d:\visual studio 2015\projects\kcf6\kcf6\源.cpp 9
danpengxie 2017-05-19
  • 打赏
  • 举报
回复
引用 7 楼 wwzh2003 的回复:
改成了读取视频的代码,已经解决
楼主最后是怎么运行的呢?求指教 谢谢
方向在前方 2017-05-09
  • 打赏
  • 举报
回复
引用 23 楼 faithallllll 的回复:
[quote=引用 7 楼 wwzh2003 的回复:] 改成了读取视频的代码,已经解决
楼主你好,我最近在学习有关kcf跟踪算法,想用这个代码来跟踪视频目标,可以编译成功,但是运行成功后直接退出,想请教一下您当时是怎么改的。[/quote]你好,请问你读取视频成功了没有,想请教一下
zr950827 2017-04-20
  • 打赏
  • 举报
回复
请问是怎么运行的,能不能麻烦给一下读取视频的代码,我也是下的这个版本的代码,最近在搞毕业设计,也是这个kcf算法的目标跟踪,点击调试只有个黑框出来,输入任何东西都没有反应,而且图片存放位置也不知道在哪,要是有读取视频的代码就好了
persimmonunderhill 2017-04-03
  • 打赏
  • 举报
回复
引用 7 楼 wwzh2003 的回复:
改成了读取视频的代码,已经解决
楼主你好,我最近在学习有关kcf跟踪算法,想用这个代码来跟踪视频目标,可以编译成功,但是运行成功后直接退出,想请教一下您当时是怎么改的。
aopaw 2016-12-16
  • 打赏
  • 举报
回复
楼主你编译过程中遇到过 ocv_add_testdata 这样的错误吗 我用 的2.4.10编译不成功 把那部分注释掉了之后遇到了 ovc_download 这个错误
leyi_bjtu 2016-11-02
  • 打赏
  • 举报
回复
引用 16 楼 Loser__Wang 的回复:
matlab的肯定是可以直接运行的。把路径改为自己的benchmark的路径就可以了。c++的版本我比较推荐作者在主页上的multi-scale的版本。
能麻烦您给一个KCF算法MATLAB版的代码吗?我在网上找了好久都没找到,作者的官网上也下载不了。。。。您有的话麻烦给我发一份呗,非常感谢!我的邮箱是leyi_bjtu@163.com
hjl240 2016-07-29
  • 打赏
  • 举报
回复
可以参考这篇博客:http://blog.csdn.net/hjl240/article/details/52002749
cultivating 2016-07-20
  • 打赏
  • 举报
回复
想请问下,有人了解知道KCF里面的样本是如何准备的吗?正/负样本。以及每个样本提取HOg特征之后,是一维吧?怎么看源码感觉像是两维
js8878 2016-06-12
  • 打赏
  • 举报
回复
引用 12 楼 DASDASDFDSFSD 的回复:
发现c++版本的比matab版本慢多了,是这样的吗?
不算慢 http://player.youku.com/player.php/sid/XMTYwNTM4NTgwOA==/v.swf
Amberrr_Li 2016-05-30
  • 打赏
  • 举报
回复
作者主页提供了四个版本,一个matlab,两个c++,都没法跑。正在搞opencv版。。。。
王强_CASIA 2016-05-24
  • 打赏
  • 举报
回复
matlab的肯定是可以直接运行的。把路径改为自己的benchmark的路径就可以了。c++的版本我比较推荐作者在主页上的multi-scale的版本。
xflnku 2016-05-23
  • 打赏
  • 举报
回复
matlab和c++要么编译不成功,要么运行不了,实在是无语,而且代码还是作者主页提供的,网上很多这样的问题,却没人愿意出来帮忙解答一下
titiwoo 2016-05-05
  • 打赏
  • 举报
回复
你好?请问你这个算法你运行成功了?可以请教一下运行结果和运行环境吗?
baidu_26338597 2016-05-02
  • 打赏
  • 举报
回复
楼主可以分享一下吗?球球:591054924 理论部分已经分析,c++的还没有能跑的
BalaJoa 2016-04-19
  • 打赏
  • 举报
回复
发现c++版本的比matab版本慢多了,是这样的吗?
toastor 2016-04-13
  • 打赏
  • 举报
回复
兄弟 你怎么改的啊 求教啊
fangzhangran956 2016-04-13
  • 打赏
  • 举报
回复
LZ能求一个KCF的代码吗?
qq_34476878 2016-03-30
  • 打赏
  • 举报
回复
楼主你好!最近我也在学习KCF这个算法,但找到的程序都编译不成功,请问你的程序可以编译运行么?
REIONE 2016-03-04
  • 打赏
  • 举报
回复
拿OPENCV3.1 可以成功 亲测
加载更多回复(7)

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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