From 7cf94825d313166c804a9aa94c170987db5c24d6 Mon Sep 17 00:00:00 2001 From: Peter Rekdal Sunde Date: Fri, 11 Oct 2019 20:16:40 +0200 Subject: [PATCH] Add support for changing class label using mouse wheel. Based on pr #127 - https://github.com/AlexeyAB/Yolo_mark/pull/127 --- main.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 43b97a22..41d1ef52 100644 --- a/main.cpp +++ b/main.cpp @@ -173,6 +173,8 @@ std::atomic right_button_click; std::atomic move_rect_id; std::atomic move_rect; std::atomic clear_marks; +std::atomic wheel_increase_obj_id; +std::atomic wheel_decrease_obj_id; std::atomic copy_previous_marks(false); std::atomic tracker_copy_previous_marks(false); @@ -244,6 +246,11 @@ void callback_mouse_click(int event, int x, int y, int flags, void* user_data) x_end = max(x, 0); y_end = max(y, 0); } + else if (event == cv::EVENT_MOUSEWHEEL) + { + wheel_decrease_obj_id = getMouseWheelDelta(flags) > 0; + wheel_increase_obj_id = wheel_decrease_obj_id ? false : true; + } } class comma : public std::numpunct { @@ -918,18 +925,27 @@ int main(int argc, char *argv[]) int pressed_key = cv::waitKey(20); // OpenCV 2.x #endif + auto old_obj_id = current_obj_id; + if (pressed_key >= 0) for (int i = 0; i < 5; ++i) cv::waitKey(1); if (exit_flag) break; // exit after saving if (pressed_key == 27 || pressed_key == 1048603) exit_flag = true;// break; // ESC - save & exit - auto old_obj_id = current_obj_id; if (pressed_key >= '0' && pressed_key <= '9') current_obj_id = pressed_key - '0'; // 0 - 9 if (pressed_key >= 1048624 && pressed_key <= 1048633) current_obj_id = pressed_key - 1048624; // 0 - 9 - if(old_obj_id != current_obj_id - && selected_id >= 0) + if(old_obj_id == current_obj_id + && (wheel_increase_obj_id || wheel_decrease_obj_id)) + { + current_obj_id = wheel_increase_obj_id ? + min(max_object_id, current_obj_id + 1) : + max(0, current_obj_id - 1); + wheel_decrease_obj_id = wheel_increase_obj_id = false; + } + + if(old_obj_id != current_obj_id && selected_id >= 0) { current_coord_vec[selected_id].id = current_obj_id; }