参考摘自《learn opencv-如何在OpenCV中选择边界框(ROI)?》https://blog.csdn.net/wc781708249/article/details/78518447
左键拉框,空格或enter结束。但只能取【1】个ROI。
#include <opencv2/opencv.hpp>
#include "opencv2/video/tracking.hpp" // selectROI is part of tracking API
using namespace std;
using namespace cv;
int main(int argc, char **arv)
{
Mat im = imread("E:/mypic/0.jpg");
Rect2d roi_img = selectROI(im); // Select ROI
Mat imCrop = im(roi_img); // Crop image
imshow("Image", imCrop); // Display Cropped Image
waitKey(0);
return 0;
}