企业网站用织梦好吗,建设网站属于什么费用,搜题公众号怎么制作,网站在哪设置关键词操作系统#xff1a;ubuntu22.04 OpenCV版本#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言#xff1a;C11
算法描述
允许用户在给定的图像上选择多个 ROI。
该函数创建一个窗口#xff0c;并允许用户使用鼠标来选择多个 ROI。控制方式#xff1a;使用空格键或… 操作系统ubuntu22.04 OpenCV版本OpenCV4.9 IDE:Visual Studio Code 编程语言C11
算法描述
允许用户在给定的图像上选择多个 ROI。
该函数创建一个窗口并允许用户使用鼠标来选择多个 ROI。控制方式使用空格键或回车键完成当前的选择并开始一个新的选择使用 ESC 键终止多个 ROI 的选择过程。
注意 该函数使用 cv::setMouseCallback(windowName, …) 为指定的窗口设置自己的鼠标回调。工作完成后将为使用的窗口设置一个空的回调。
函数原型
void cv::selectROIs
(const String windowName,InputArray img,std::vector Rect boundingBoxes,bool showCrosshair true,bool fromCenter false,bool printNotice true
) 参数
参数windowName 显示选择过程的窗口的名称。参数wimg 用于选择 ROI 的图像。参数wboundingBoxes 选定的 ROIs。参数wshowCrosshair 如果为真则将显示选择矩形的十字光标。参数wfromCenter 如果为真则选择的中心将匹配初始鼠标位置。相反的情况下选择矩形的一个角将对应于初始鼠标位置。参数wprintNotice 如果为真则将在控制台中打印选择 ROI 或取消选择的通知。
代码示例
#include iostream
#include opencv2/opencv.hppint main()
{// 加载图像cv::Mat img cv::imread( /media/dingxin/data/study/OpenCV/sources/images/hawk.jpg, cv::IMREAD_COLOR );if ( img.empty() ){std::cerr Error: Image not found! std::endl;return -1;}// 创建窗口std::string windowName Select ROIs;cv::namedWindow( windowName, cv::WINDOW_NORMAL );// 显示图像cv::imshow( windowName, img );// 准备存储 ROI 的向量std::vector cv::Rect boundingBoxes;// 提示用户如何进行选择std::cout Use the mouse to draw rectangles around the regions you want to select. Press space or enter to confirm a selection and start a new one. Press ESC to finish the selection process. std::endl;// 选择 ROIscv::selectROIs( windowName, img, boundingBoxes, false, false, true );// 检查是否有 ROI 被选中if ( !boundingBoxes.empty() ){// 打印所选区域的信息std::cout Selected ROIs: std::endl;for ( const auto roi : boundingBoxes ){std::cout ROI at ( roi.x , roi.y ) with size ( roi.width , roi.height ) std::endl;}// 在原图上画出所选区域的边界框for ( const auto roi : boundingBoxes ){cv::rectangle( img, roi, cv::Scalar( 0, 255, 0 ), 2 );}// 显示带有边界框的图像cv::imshow( windowName, img );cv::waitKey( 0 ); // 等待用户按键}else{std::cout No ROIs were selected. std::endl;}// 关闭所有窗口cv::destroyAllWindows();return 0;
}运行结果