diff --git a/modules/highgui/include/opencv2/highgui.hpp b/modules/highgui/include/opencv2/highgui.hpp index 7ae2395737..32f6dfb25d 100644 --- a/modules/highgui/include/opencv2/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui.hpp @@ -520,16 +520,17 @@ Controls: use `space` or `enter` to finish selection, use key `c` to cancel sele @param showCrosshair if true crosshair of selection rectangle will be shown. @param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of selection rectangle will correspont to the initial mouse position. +@param printNotice if true a notice to select ROI or cancel selection will be printed in console. @return selected ROI or empty rect if selection canceled. @note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). After finish of work an empty callback will be set for the used window. */ -CV_EXPORTS_W Rect selectROI(const String& windowName, InputArray img, bool showCrosshair = true, bool fromCenter = false); +CV_EXPORTS_W Rect selectROI(const String& windowName, InputArray img, bool showCrosshair = true, bool fromCenter = false, bool printNotice = true); /** @overload */ -CV_EXPORTS_W Rect selectROI(InputArray img, bool showCrosshair = true, bool fromCenter = false); +CV_EXPORTS_W Rect selectROI(InputArray img, bool showCrosshair = true, bool fromCenter = false, bool printNotice = true); /** @brief Allows users to select multiple ROIs on the given image. @@ -543,12 +544,13 @@ use `esc` to terminate multiple ROI selection process. @param showCrosshair if true crosshair of selection rectangle will be shown. @param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of selection rectangle will correspont to the initial mouse position. +@param printNotice if true a notice to select ROI or cancel selection will be printed in console. @note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). After finish of work an empty callback will be set for the used window. */ CV_EXPORTS_W void selectROIs(const String& windowName, InputArray img, - CV_OUT std::vector& boundingBoxes, bool showCrosshair = true, bool fromCenter = false); + CV_OUT std::vector& boundingBoxes, bool showCrosshair = true, bool fromCenter = false, bool printNotice = true); /** @brief Creates a trackbar and attaches it to the specified window. diff --git a/modules/highgui/src/roiSelector.cpp b/modules/highgui/src/roiSelector.cpp index 4fba07eacb..1bbd246c05 100644 --- a/modules/highgui/src/roiSelector.cpp +++ b/modules/highgui/src/roiSelector.cpp @@ -13,11 +13,14 @@ namespace class ROISelector { public: - Rect select(const String &windowName, Mat img, bool showCrossair = true, bool fromCenter = true) + Rect select(const String &windowName, Mat img, bool showCrossair = true, bool fromCenter = true, bool printNotice = true) { - // show notice to user - printf("Select a ROI and then press SPACE or ENTER button!\n"); - printf("Cancel the selection process by pressing c button!\n"); + if(printNotice) + { + // show notice to user + printf("Select a ROI and then press SPACE or ENTER button!\n"); + printf("Cancel the selection process by pressing c button!\n"); + } key = 0; imageSize = img.size(); @@ -83,16 +86,19 @@ class ROISelector } void select(const String &windowName, Mat img, std::vector &boundingBoxes, - bool showCrosshair = true, bool fromCenter = true) + bool showCrosshair = true, bool fromCenter = true, bool printNotice = true) { - printf("Finish the selection process by pressing ESC button!\n"); + if(printNotice) + { + printf("Finish the selection process by pressing ESC button!\n"); + } boundingBoxes.clear(); key = 0; // while key is not ESC (27) for (;;) { - Rect temp = select(windowName, img, showCrosshair, fromCenter); + Rect temp = select(windowName, img, showCrosshair, fromCenter, printNotice); if (key == 27) break; if (temp.width > 0 && temp.height > 0) @@ -195,21 +201,21 @@ class ROISelector }; } -Rect cv::selectROI(InputArray img, bool showCrosshair, bool fromCenter) +Rect cv::selectROI(InputArray img, bool showCrosshair, bool fromCenter, bool printNotice) { ROISelector selector; - return selector.select("ROI selector", img.getMat(), showCrosshair, fromCenter); + return selector.select("ROI selector", img.getMat(), showCrosshair, fromCenter, printNotice); } -Rect cv::selectROI(const String& windowName, InputArray img, bool showCrosshair, bool fromCenter) +Rect cv::selectROI(const String& windowName, InputArray img, bool showCrosshair, bool fromCenter, bool printNotice) { ROISelector selector; - return selector.select(windowName, img.getMat(), showCrosshair, fromCenter); + return selector.select(windowName, img.getMat(), showCrosshair, fromCenter, printNotice); } void cv::selectROIs(const String& windowName, InputArray img, - std::vector& boundingBox, bool showCrosshair, bool fromCenter) + std::vector& boundingBox, bool showCrosshair, bool fromCenter, bool printNotice) { ROISelector selector; - selector.select(windowName, img.getMat(), boundingBox, showCrosshair, fromCenter); + selector.select(windowName, img.getMat(), boundingBox, showCrosshair, fromCenter, printNotice); }