diff options
Diffstat (limited to 'src/ui.cc')
-rw-r--r-- | src/ui.cc | 48 |
1 files changed, 36 insertions, 12 deletions
@@ -73,29 +73,52 @@ namespace frontend { return false; } + backend::label* getCurrentRectLabel(ui_impl *data) { + auto labs = data->llr->getEditableLabels(); + for(auto rit = labs.rbegin(); rit != labs.rend(); rit++) { + if(rit->location.nonzero()) { + return &(*rit); + } + } + return nullptr; + } + void mouseCallback(int event, int x, int y, int flags, void* userdata) { // userdata is actually a &shared_ptr<ui_impl> - shared_ptr<ui_impl> data = (shared_ptr<ui_impl>) *userdata; + auto data = static_cast<ui_impl*>(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 { - + double time = data->pb->getTime(); + auto lab = getCurrentRectLabel(data); + if(lab && lab->time == time) { + // Use this one + } else { // Make one + // Try to use the first rectangle annotation, fall back on normal, then "Rectangle" + std::string name = "Rectangle"; + if(!data->llr->getRectangleLabels().empty()) { + name = data->llr->getRectangleLabels()[0]; + } else if(!data->llr->getLabels().empty()) { + name = data->llr->getLabels()[0]; + } + data->llr->applyLabel(name, time); + lab = &data->llr->getEditableLabels().back(); } + lab->location.x1 = x; + lab->location.y1 = y; } 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 + if(mouseDown) { + auto lab = getCurrentRectLabel(data); // It will be valid! TODO: Will it? + std::cout << "Updating location from " << lab->location.x2 << ", " << lab->location.y2 << " to " << x << ", " << y << "\n"; + lab->location.x2 = x; + lab->location.y2 = y; + } } } @@ -111,9 +134,10 @@ namespace frontend { ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); int cols = size.ws_col; // Register mouse callback - cv::setMouseCallback("Video", mouseCallback, &data); + data->pb->display("Video", (getCurrentRectLabel(data.get()))? getCurrentRectLabel(data.get())->location : backend::rect()); + cv::setMouseCallback("Video", mouseCallback, data.get()); while(true) { - data->pb->display("Video"); + data->pb->display("Video", (getCurrentRectLabel(data.get()))? getCurrentRectLabel(data.get())->location : backend::rect()); data->pb->interFrameSleep(); if(handleKey(cv::pollKey(), data)) { break; |