diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/labeller.cc | 23 | ||||
-rw-r--r-- | src/labeller.h | 3 | ||||
-rw-r--r-- | src/playback.cc | 4 | ||||
-rw-r--r-- | src/ui.cc | 22 |
4 files changed, 37 insertions, 15 deletions
diff --git a/src/labeller.cc b/src/labeller.cc index ea72db0..d64ac93 100644 --- a/src/labeller.cc +++ b/src/labeller.cc @@ -19,12 +19,27 @@ namespace backend { std::string line; const char delim = ','; while(std::getline(in, line)) { - std::size_t split = line.find(delim); - if(split == std::string::npos) { + // Fields are label,time,x1,y1,x2,y2 + std::vector<std::string> parts; + std::size_t split; + while((split = line.find(delim)) != std::string::npos) { + parts.push_back(line.substr(0, split)); + line = line.substr(split+1); + } + // And pick up that last part + parts.push_back(line); + if(parts.size() < 2) { 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)))); + label lab(parts[0], std::stod(parts[1])); + if(parts.size() == 6) { + lab.location.x1 = std::stoi(parts[2]); + lab.location.y1 = std::stoi(parts[3]); + lab.location.x2 = std::stoi(parts[4]); + lab.location.y2 = std::stoi(parts[5]); + } + data.annotations.push_back(lab); } } @@ -138,7 +153,7 @@ namespace backend { std::vector<label> a(data->annotations); std::sort(a.begin(), a.end(), compareLabels); for(label l : a) { - out << l.name << "," << l.time << std::endl; + out << l.name << "," << l.time << "," << l.location.string() << std::endl; } out.close(); } diff --git a/src/labeller.h b/src/labeller.h index cf108f5..37a2eda 100644 --- a/src/labeller.h +++ b/src/labeller.h @@ -13,6 +13,9 @@ namespace backend { bool nonzero() const { return (x1 != 0 || x1 != 0 || y1 != 0 || y2 != 0); } + std::string string() { + return std::to_string(x1) + "," + std::to_string(y1) + "," + std::to_string(x2) + "," + std::to_string(y2); + } }; struct label { diff --git a/src/playback.cc b/src/playback.cc index bbc2649..700567a 100644 --- a/src/playback.cc +++ b/src/playback.cc @@ -33,12 +33,12 @@ namespace frontend { } void playback::display(const std::string& windowName, const backend::rect &r) const { - cv::Mat curr(data->images[data->frameNum]); + cv::Mat curr = data->images[data->frameNum].clone(); if(r.nonzero()) { // Update with the rectangle cv::rectangle(curr, cv::Point(r.x1, r.y1), cv::Point(r.x2, r.y2), cv::Scalar(255, 0, 0), 2, cv::LINE_8); } - cv::imshow(windowName, data->images[data->frameNum]); + cv::imshow(windowName, curr); } bool playback::seekFrame(std::size_t frameNum) { @@ -36,20 +36,24 @@ namespace frontend { case 32: // Space pauses data->play = ! data->play; break; - case 65361: // Left seeks backward 1 frame + case 104: + case 65361: // Left seeks backward 1 frame (or h) data->pb->seekFrame(data->pb->getFrame() - 1); break; - case 65362: // Up seeks backward 1 second + case 100: + case 65362: // Up seeks backward 1 second (or d) if(data->pb->getTime() < 1) { data->pb->seekTime(data->pb->getTime() * -1); } else { data->pb->seekTime(data->pb->getTime() - 1); } break; - case 65363: // Right seeks forward 1 frame + case 116: + case 65363: // Right seeks forward 1 frame (or t) data->pb->seekFrame(data->pb->getFrame() + 1); break; - case 65364: // Down seeks forward 1 second + case 110: + case 65364: // Down seeks forward 1 second (or n) data->pb->seekTime(data->pb->getTime() + 1); break; case 117: // u undoes @@ -74,9 +78,9 @@ namespace frontend { } backend::label* getCurrentRectLabel(ui_impl *data) { - auto labs = data->llr->getEditableLabels(); + auto &labs = data->llr->getEditableLabels(); for(auto rit = labs.rbegin(); rit != labs.rend(); rit++) { - if(rit->location.nonzero()) { + if(rit->location.nonzero() && rit->time <= data->pb->getTime()) { return &(*rit); } } @@ -106,8 +110,8 @@ namespace frontend { data->llr->applyLabel(name, time); lab = &data->llr->getEditableLabels().back(); } - lab->location.x1 = x; - lab->location.y1 = y; + lab->location.x1 = lab->location.x2 = x; + lab->location.y1 = lab->location.y2 = y; } else if(event == cv::EVENT_LBUTTONUP) { // Mouse is no longer down mouseDown = false; @@ -115,7 +119,7 @@ namespace frontend { // 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"; + //std::cout << "Updating location from " << lab->location.x2 << ", " << lab->location.y2 << " to " << x << ", " << y << "\n"; lab->location.x2 = x; lab->location.y2 = y; } |