From 8a6b5564c0fc37e6e556d04e17ddba86d4bd3dc1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 17 Aug 2021 08:56:06 -0400 Subject: Started work on bounding boxes --- src/ui.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/ui.cc') diff --git a/src/ui.cc b/src/ui.cc index 3d0e193..858d74c 100644 --- a/src/ui.cc +++ b/src/ui.cc @@ -73,6 +73,32 @@ namespace frontend { return false; } + void mouseCallback(int event, int x, int y, int flags, void* userdata) { + // userdata is actually a &shared_ptr + shared_ptr data = (shared_ptr) *userdata; + static bool mouseDown = false; + // We're interested in left button down/up and movement when down + if(event == cv::EVENT_LBUTTONDOWN) { + // If the current frame doesn't have a rectangle label, then make one + mouseDown = true; + double time = data->pb->getTime() + auto labs = data->llr->getSurrounding(time); + backend::label current; + if(labs.first.time == time) { + current = labs.first; + } else if(labs.second.time == time) { + current = labs.second; + } else { + + } + } else if(event == cv::EVENT_LBUTTONUP) { + // Mouse is no longer down + mouseDown = false; + } else if(event == cv::EVENT_MOUSEMOVE) { + // If the mouse is down, update x2 and y2 of current window + } + } + void ui::begin() { std::cout << "Playing a video that's " << data->pb->getMaxFrame() << " frames (" << data->pb->getMaxTime() << " seconds) long." << std::endl; std::cout << "Annotations:" << std::endl; @@ -84,6 +110,8 @@ namespace frontend { struct winsize size; ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); int cols = size.ws_col; + // Register mouse callback + cv::setMouseCallback("Video", mouseCallback, &data); while(true) { data->pb->display("Video"); data->pb->interFrameSleep(); -- cgit v1.2.3