int main(){ cv::Mat m1(5,5, CV_8UC1); for(int i=0;i<m1.rows;++i) for(int j=0;j<m1.cols;++j) m1.at<uchar>(i,j)=i*2+j*2+1; // uchar与8U匹配。 std::cout<<m1<<std::endl; std::cout<<std::endl; cv::Mat roi1=m1(cv::Rect(cv::Point(2,1),cv::Point(3,2))); // Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); std::cout<<roi1<<std::endl; std::cout<<std::endl; cv::Mat roi2=m1(cv::Rect(2,1,1,1)); // Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); std::cout<<roi2<<std::endl; std::cout<<std::endl; cv::Mat roi3=m1(cv::Rect(cv::Point(2,1),cv::Size(1,1))); // Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2) std::cout<<roi3<<std::endl; std::cout<<std::endl; return 0; }