windows下多尺度kcf算法運行

把作者multiscale版本runtracker.cpp改爲

//runkcftracker.cpp文件
#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;


	bool flag = false;
	string root_path = "E:\\DataSets\\OTB100\\Human6\\img\\";
	vector<String> img_paths;
	glob(root_path, img_paths);
	int key;
	string path;

	// 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;
	for (int i = 0; i < img_paths.size(); i++) {
		path = img_paths[i];
		if (!flag) {
			flag = true;
			frame = imread(path);
			result = selectROI("Tracking", frame);
			tracker.init(result, frame);
		}
		else {
			frame = imread(path);
			result = tracker.update(frame);
			rectangle(frame, Point(result.x, result.y), Point(result.x + result.width, result.y + result.height), Scalar(255, 0, 0), 1, 8);
			imshow("Tracking", frame);
			key = waitKey(1);
			if (key == 27) break;
		}

	}


























	/*
	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();
	*/



}

其他文件不變

在這裏插入圖片描述在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章