- 使用Rect(Point pt1, Point pt2)定义一个矩形区域用于截取Mat,选定区域左上角的坐标为(pt1.x, pt1.y),右下角的坐标为(pt2.x - 1, pt2.y - 1),区域宽为pt2.x - pt1.x,高为pt2.y - pt1.y。
- 为防止直接使用Rect截取区域报错,可以使用
Mat Mat1(10, 10, CV_8UC1, Scalar(0));
Rect Rect1 = Rect(Point(3, 3), Point(7, 7));
Rect Rect2 = Rect1 & Rect(0, 0, Mat1.cols, Mat2.rows);
Mat Mat2 = Mat1(Rect2);
的方式从Mat1中截取Mat2。