Skip to content

Commit

Permalink
Big refactoring and name change
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmurray committed May 10, 2017
1 parent 342b184 commit 07c247c
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ $ ./trackApp.out [-s sequencesFile] [-m modelConfigFile]
```

## Integrate in other projects
* To detect objects from images, create an instance of `BBDetector`. Requires Caffe. Use function `detector.detect(<image>)`.
* To track objects from pre-existing detections, create an instance of `MCSORT`. No code in `detector/` is needed. Use function `tracker.track(<detections>)`.
* To detect objects from images, create an instance of `SSDDetector`. Requires Caffe. Use function `detector.detect(<image>)`.
* To track objects from pre-existing detections, create an instance of `PAOT`. No code in `detector/` is needed. Use function `tracker.track(<detections>)`.
* To detect and track objects from images, create an instance of `ImageTracker`. Requires Caffe. Use function `tracker.detectAndTrack(<image>)`.
12 changes: 6 additions & 6 deletions cpp/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ TARGET_track := trackApp.out
TARGET_detectAndTrack := detectAndTrackApp.out
TARGETS := $(TARGET_detect) $(TARGET_track) $(TARGET_detectAndTrack)

# For running Detect.cpp
# For running DetectDemo.cpp
OBJECTS_detect := $(filter-out $(BUILDDIR)/$(MAINDIR)/%.o,$(OBJECTS))
OBJECTS_detect += $(BUILDDIR)/$(MAINDIR)/Detect.o
OBJECTS_detect += $(BUILDDIR)/$(MAINDIR)/DetectDemo.o

# For running Track.cpp
# For running TrackDemo.cpp
OBJECTS_track := $(filter-out $(BUILDDIR)/$(MAINDIR)/%.o,$(OBJECTS))
OBJECTS_track += $(BUILDDIR)/$(MAINDIR)/Track.o
OBJECTS_track += $(BUILDDIR)/$(MAINDIR)/TrackDemo.o

# For running DetectAndTrack.cpp
# For running DetectAndTrackDemo.cpp
OBJECTS_detectAndTrack := $(filter-out $(BUILDDIR)/$(MAINDIR)/%.o,$(OBJECTS))
OBJECTS_detectAndTrack += $(BUILDDIR)/$(MAINDIR)/DetectAndTrack.o
OBJECTS_detectAndTrack += $(BUILDDIR)/$(MAINDIR)/DetectAndTrackDemo.o

# Build instructioncs
MKDIRIFNOTEXIST = @test -d $(@D) || mkdir -p $(@D)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../ImageTracker.h"
#include "../detector/RandomDetector.h"
#include "../detector/SSDDetector.h"
#include "../tracker/mcsort/MCSORT.h"
#include "../tracker/PAOT.h"

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
Expand Down Expand Up @@ -63,7 +63,7 @@ std::pair<std::chrono::duration<double, std::milli>, int> detectAndTrack(const s
exit(EXIT_FAILURE);
}

ImageTracker imageTracker(detector, std::make_shared<MCSORT>());
ImageTracker imageTracker(detector, std::make_shared<PAOT>());

std::vector<boost::filesystem::path> imagePaths;
std::copy(boost::filesystem::directory_iterator(inputDirPath),
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions cpp/src/examples/Track.cpp → cpp/src/examples/TrackDemo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "../tracker/Tracker.h"
#include "../tracker/mcsort/MCSORT.h"
#include "../tracker/PAOT.h"
#include "../util/DetectionFileParser.h"

#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -43,8 +43,8 @@ std::pair<std::chrono::duration<double, std::milli>, int> track(const boost::fil
// Make sure output file does not exist
boost::filesystem::path outputPath = outputDirPath / (sequencePath.filename().string() + ".txt");
if (boost::filesystem::exists(outputPath)) {
fprintf(stderr, FILE_EXISTS_MESSAGE, outputPath.c_str());
return std::pair<msduration, int>(msduration(0), 0);
fprintf(stderr, FILE_EXISTS_MESSAGE, outputPath.c_str()); // FIXME:
//return std::pair<msduration, int>(msduration(0), 0);
}

// Make sure output file can be opened
Expand All @@ -55,7 +55,7 @@ std::pair<std::chrono::duration<double, std::milli>, int> track(const boost::fil
exit(EXIT_FAILURE);
}

MCSORT tracker;
PAOT tracker;

std::map<int, std::vector<Detection>> (*parseFileFunc)(std::ifstream &file);
if (detectionFormat == "okutama") {
Expand All @@ -70,6 +70,7 @@ std::pair<std::chrono::duration<double, std::milli>, int> track(const boost::fil
msduration cumulativeDuration = std::chrono::milliseconds::zero();
int frameCount = 0;
for (int frame = 0; frame < frameToDetections.rbegin()->first; ++frame) {
std::cout << frame << std::endl;
if (frame % frameInterval == 0 && frameToDetections.find(frame) != frameToDetections.end()) {
auto startTime = std::chrono::high_resolution_clock::now();
std::vector<Tracking> trackings = tracker.track(frameToDetections.at(frame));
Expand Down
16 changes: 8 additions & 8 deletions cpp/src/tracker/mcsort/MCSORT.cpp → cpp/src/tracker/PAOT.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "MCSORT.h"
#include "PAOT.h"

#include "../Affinity.h"
#include "kalman/KalmanPredictor.h"
#include "particle/ParticlePredictor.h"
#include "Affinity.h"
#include "predictor/kalman/KalmanPredictor.h"
#include "predictor/particle/ParticlePredictor.h"

#include <dlib/optimization.h>

// Methods

std::vector<Tracking> MCSORT::track(const std::vector<Detection> &detections) {
std::vector<Tracking> PAOT::track(const std::vector<Detection> &detections) {
frameCount++;

// Filter detections on confidence
Expand Down Expand Up @@ -56,7 +56,7 @@ std::vector<Tracking> MCSORT::track(const std::vector<Detection> &detections) {
return trackings;
}

MCSORT::Association MCSORT::associateDetectionsToPredictors(
PAOT::Association PAOT::associateDetectionsToPredictors(
const std::vector<Detection> &detections,
const std::vector<std::shared_ptr<Predictor>> &predictors,
double (*affinityMeasure)(const BoundingBox &a, const BoundingBox &b),
Expand All @@ -70,7 +70,7 @@ MCSORT::Association MCSORT::associateDetectionsToPredictors(
if (predictors.empty()) {
for (int i = 0; i < detections.size(); ++i)
unmatchedDetections.push_back(i);
return MCSORT::Association{matches, unmatchedDetections, unmatchedPredictors};
return PAOT::Association{matches, unmatchedDetections, unmatchedPredictors};
}

dlib::matrix<int> cost(detections.size(), predictors.size());
Expand Down Expand Up @@ -104,5 +104,5 @@ MCSORT::Association MCSORT::associateDetectionsToPredictors(
matches.push_back(std::pair<int, int>(d, assignment[d]));
}
}
return MCSORT::Association{matches, unmatchedDetections, unmatchedPredictors};
return PAOT::Association{matches, unmatchedDetections, unmatchedPredictors};
}
17 changes: 8 additions & 9 deletions cpp/src/tracker/mcsort/MCSORT.h → cpp/src/tracker/PAOT.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#ifndef CPP_MCSORT_H
#define CPP_MCSORT_H
#ifndef CPP_PAOT_H
#define CPP_PAOT_H


#include "../Tracker.h"
#include "Predictor.h"
#include "kalman/KalmanPredictor.h"
#include "Tracker.h"
#include "predictor/Predictor.h"
#include "predictor/kalman/KalmanPredictor.h"

#include <memory>
#include <vector>

class MCSORT : public Tracker {
class PAOT : public Tracker {
struct Association;

public:
MCSORT() = default;
PAOT() = default;

virtual ~MCSORT() = default;
virtual ~PAOT() = default;

/**
* Uses a linear velocity Kalman filters to predict locations of objects from previous frame.
Expand All @@ -29,7 +29,6 @@ class MCSORT : public Tracker {
const double detectionThreshold = 0.4;
const double affinityThreshold = 0.1;
std::vector<std::shared_ptr<Predictor>> predictors;
//std::map<int, int> perLabelCount;
int trackCount = 0;
int frameCount = 0;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 07c247c

Please sign in to comment.