From 5e4240ea795c992635a3cfc464d760205e07bf05 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 17 Aug 2021 08:54:45 -0400 Subject: Updated keys --- src/annotator.cc | 12 ++++++++---- src/labeller.cc | 21 ++++++++++++++++++++- src/playback.cc | 4 ++-- src/playback.h | 2 +- src/ui.cc | 8 ++++---- 5 files changed, 35 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/annotator.cc b/src/annotator.cc index f1fccbc..1a6d557 100644 --- a/src/annotator.cc +++ b/src/annotator.cc @@ -29,14 +29,18 @@ int main(int argc, char *argv[]) { std::vector flags = extractFlags(args); if(args.empty()) { std::cout << "Must provide a path to a video to process!" << std::endl; + return 1; + } + int frameCap = -1; + if(args.size() >= 2) { + frameCap = std::stoi(args[1]); + std::cout << "Only using first " << frameCap << " frames." << std::endl; } std::cout << "Loading video " << args[0] << std::endl; std::filesystem::path p(args[0]); - std::shared_ptr playback(new frontend::playback(p)); + std::shared_ptr playback(new frontend::playback(p, frameCap)); // Format save path - auto savedir = std::filesystem::path("save") / p.parent_path().filename(); - std::filesystem::create_directories(savedir); - auto savepath = savedir / (p.stem().string() + ".csv"); + auto savepath = std::filesystem::path("saves") / p.parent_path().filename() / (p.stem().string() + ".csv"); std::cout << "Saves are written to: " << savepath << std::endl; std::shared_ptr labeller(new backend::labeller(savepath)); frontend::ui ui(playback, labeller); diff --git a/src/labeller.cc b/src/labeller.cc index 64da2d7..32f69c9 100644 --- a/src/labeller.cc +++ b/src/labeller.cc @@ -1,7 +1,7 @@ #include "labeller.h" #include "settings.h" #include - +#include namespace backend { struct labeller_impl { @@ -13,10 +13,27 @@ namespace backend { std::filesystem::path savepath; }; + void load(const std::filesystem::path& savepath, labeller_impl& data) { + std::ifstream in(savepath); + std::string line; + const char delim = ','; + while(std::getline(in, line)) { + std::size_t split = line.find(delim); + if(split == std::string::npos) { + std::cerr << "Error reading " << savepath << std::endl; + throw std::runtime_error(savepath.string()); + } + data.annotations.push_back(label(line.substr(0, split), std::stod(line.substr(split+1)))); + } + } + labeller::labeller(const std::filesystem::path& savepath) { data = std::shared_ptr(new labeller_impl); data->labels = settings::getLabels(); data->savepath = savepath; + if(std::filesystem::directory_entry(savepath).exists()) { + load(savepath, *data); + } } std::pair labeller::getSurrounding(double time) const { @@ -105,6 +122,7 @@ namespace backend { void labeller::save() const { std::ofstream out; + std::filesystem::create_directories(data->savepath.parent_path()); out.open(data->savepath); std::vector