这个KCF跟踪算法如何运行?
我用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
该怎么编译呢?