From 5a6248518654ec97d95d2c463e3ffb4be7bbf456 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 13 May 2021 17:20:26 -0400 Subject: Initial commit --- .gitignore | 2 + Makefile | 39 +++++++++++++++++++ annotator.conf | 1 + configure | 80 ++++++++++++++++++++++++++++++++++++++ src/annotator.cc | 45 +++++++++++++++++++++ src/labeller.cc | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/labeller.h | 32 +++++++++++++++ src/playback.cc | 69 +++++++++++++++++++++++++++++++++ src/playback.h | 23 +++++++++++ src/settings.cc | 28 ++++++++++++++ src/settings.h | 7 ++++ src/ui.cc | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ui.h | 19 +++++++++ 13 files changed, 576 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 annotator.conf create mode 100755 configure create mode 100644 src/annotator.cc create mode 100644 src/labeller.cc create mode 100644 src/labeller.h create mode 100644 src/playback.cc create mode 100644 src/playback.h create mode 100644 src/settings.cc create mode 100644 src/settings.h create mode 100644 src/ui.cc create mode 100644 src/ui.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6443e30 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +annotator +*.o diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8cc7873 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +CC=g++ +LIBS=libconfuse opencv4 +CFLAGS=-c -Wall -fPIC -std=c++20 +LDFLAGS=-pthread +SOURCES=src/annotator.cc src/labeller.cc src/playback.cc src/settings.cc src/ui.cc +OBJECTS=$(SOURCES:.cc=.o) +LIBRARY= +EXECUTABLE=annotator +ifeq ($(PREFIX),) + PREFIX := /usr +endif + +all: $(SOURCES) $(EXECUTABLE) + +install: $(EXECUTABLE) + install -d $(DESTDIR)$(PREFIX)/bin/ + install -m 755 $(EXECUTABLE) $(DESTDIR)$(PREFIX)/bin/ + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(OBJECTS) -o $@ $(LDFLAGS) `pkg-config $(LIBS) --libs` + + +src/annotator.o: src/annotator.cc src/playback.h src/ui.h src/labeller.h + $(CC) $(CFLAGS) $< -o $@ `pkg-config $(LIBS) --cflags` + +src/labeller.o: src/labeller.cc src/labeller.h src/settings.h + $(CC) $(CFLAGS) $< -o $@ `pkg-config $(LIBS) --cflags` + +src/playback.o: src/playback.cc src/playback.h + $(CC) $(CFLAGS) $< -o $@ `pkg-config $(LIBS) --cflags` + +src/settings.o: src/settings.cc src/settings.h + $(CC) $(CFLAGS) $< -o $@ `pkg-config $(LIBS) --cflags` + +src/ui.o: src/ui.cc src/ui.h src/playback.h src/labeller.h + $(CC) $(CFLAGS) $< -o $@ `pkg-config $(LIBS) --cflags` + +clean: + rm -f src/*.o $(LIBRARY) $(EXECUTABLE) diff --git a/annotator.conf b/annotator.conf new file mode 100644 index 0000000..d89676d --- /dev/null +++ b/annotator.conf @@ -0,0 +1 @@ +labels = {"saccade", "blink", "head move start", "head move end", "look down start", "look down end"} diff --git a/configure b/configure new file mode 100755 index 0000000..9d1c65c --- /dev/null +++ b/configure @@ -0,0 +1,80 @@ +#!/bin/bash + +# These are the project-specific variables + +EXECUTABLE="annotator" + +# e.g., foo.so +LIBRARY= + +# List of libs as given to pkg-config +LIBS="libconfuse opencv4" + +CFLAGS="-c -Wall -fPIC -std=c++20" + +LDFLAGS="-pthread" + +SOURCE_DIR="src" + +EXTRAS= + +INSTALL=" +install: \$(EXECUTABLE) + install -d \$(DESTDIR)\$(PREFIX)/bin/ + install -m 755 \$(EXECUTABLE) \$(DESTDIR)\$(PREFIX)/bin/ +" + +# Below here shouldn't need editing + +SOURCES=`ls $SOURCE_DIR/*.cc | tr '\n' ' '` + +PKG_CONFIG_CFLAGS= +PKG_CONFIG_LIBS= +if [ -n "$LIBS" ]; then + PKG_CONFIG_CFLAGS='`pkg-config $(LIBS) --cflags`' + PKG_CONFIG_LIBS='`pkg-config $(LIBS) --libs`' +fi + +ALL="all: \$(SOURCES)" + +LIBRULE= +if [ -n "$LIBRARY" ]; then + LIBRULE=" +\$(LIBRARY): \$(OBJECTS) + \$(CC) \$(OBJECTS) -shared -o \$@ \$(LDFLAGS) $PKG_CONFIG_LIBS +" + ALL="$ALL \$(LIBRARY)" +fi + +EXERULE= +if [ -n "$EXECUTABLE" ]; then + EXERULE=" +\$(EXECUTABLE): \$(OBJECTS) + \$(CC) \$(OBJECTS) -o \$@ \$(LDFLAGS) $PKG_CONFIG_LIBS +" + ALL="$ALL \$(EXECUTABLE)" +fi + +ORULES=$(for cc in `ls $SOURCE_DIR/*.cc`; do g++ -MM -MT `cut -d'.' -f-1 <<< $cc`.o $cc; echo -e "\t"'$(CC) $(CFLAGS) $< -o $@ '"$PKG_CONFIG_CFLAGS\n"; done) + +cat << EOF > Makefile +CC=g++ +LIBS=$LIBS +CFLAGS=$CFLAGS +LDFLAGS=$LDFLAGS +SOURCES=$SOURCES +OBJECTS=\$(SOURCES:.cc=.o) +LIBRARY=$LIBRARY +EXECUTABLE=$EXECUTABLE +ifeq (\$(PREFIX),) + PREFIX := /usr +endif + +$ALL +$EXTRAS$INSTALL$LIBRULE$EXERULE + +$ORULES + +clean: + rm -f $SOURCE_DIR/*.o \$(LIBRARY) \$(EXECUTABLE) +EOF diff --git a/src/annotator.cc b/src/annotator.cc new file mode 100644 index 0000000..c74f04f --- /dev/null +++ b/src/annotator.cc @@ -0,0 +1,45 @@ +#include "playback.h" +#include "ui.h" +#include "labeller.h" +#include +#include +#include + +// Removes flags from args (in-place) and returns vector of flags +std::vector extractFlags(std::vector& args) { + std::vector ret; + auto it = args.begin(); + while(it != args.end()) { + if((*it)[0] == '-') { + while((*it)[0] == '-') { + (*it).erase((*it).begin()); + } + ret.push_back(*it); + args.erase(it); + } else { + it++; + } + } + return ret; +} + +int main(int argc, char *argv[]) { + std::string exename = argv[0]; + std::vector args(&argv[1], &argv[argc]); + std::vector flags = extractFlags(args); + if(args.empty()) { + std::cout << "Must provide a path to a video to process!" << std::endl; + } + std::cout << "Loading video " << args[0] << std::endl; + std::filesystem::path p(args[0]); + std::shared_ptr playback(new frontend::playback(p)); + // Format save path + auto savedir = std::filesystem::path("save") / p.parent_path().filename(); + std::filesystem::create_directories(savedir); + auto savepath = savedir / (p.stem().string() + ".txt"); + std::cout << "Saves are written to: " << savepath << std::endl; + std::shared_ptr labeller(new backend::labeller(savepath)); + frontend::ui ui(playback, labeller); + ui.begin(); + return 0; +} diff --git a/src/labeller.cc b/src/labeller.cc new file mode 100644 index 0000000..64da2d7 --- /dev/null +++ b/src/labeller.cc @@ -0,0 +1,116 @@ +#include "labeller.h" +#include "settings.h" +#include + + +namespace backend { + struct labeller_impl { + std::vector labels; + std::vector