OpenCv图像裁剪指点区域_roi

两种方式Range和ROI

#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

void testrange(Mat &img)
{
    int m = img.rows;
    int n = img.cols;
    Mat temp = img(Range(0,m*0.8), Range(0,n*0.8));
    namedWindow("Range");
    imshow("Range", temp);
}

void testroi(Mat &img)
{
    int m = img.rows;
    int n = img.cols;
    Rect rect(0,0,n*0.8, m*0.8);
    Mat temp(img, rect);
    namedWindow("roi");
    imshow("roi", temp);
}

void main()
{
    Mat img = imread("lena.jpg",0);
    namedWindow("src");
    imshow("src", img);
    testroi(img);
    testrange(img);
    waitKey(0);
}

 

posted on 2015-07-04 11:01  Maddock  阅读(9956)  评论(1编辑  收藏  举报

导航