OpenCV常用知识点

提取感兴趣区域(ROI)

1、图像格式:Iplimage

 
  
int main( int argc, char** argv )
{
   //导入图像
   IplImage *img1 = cvLoadImage("lena.jpg", 1);
   //设置感兴趣区域
   cvSetImageROI(img1, cvRect(10, 15, 150, 250));
   //感兴趣区域大小一样
   IplImage *img2 = cvCreateImage(cvGetSize(img1),img1->depth,img1->nChannels);
   //拷贝
   cvCopy(img1, img2, NULL);
 
   //重置
   cvResetImageROI(img1);

   cvNamedWindow("img1");
   cvNamedWindow("img2");
   cvShowImage("img1",img1);
   cvShowImage("img2",img2);

   cvWaitKey(0);
   cvDestroyAllWindows();
   cvReleaseImage(&img1);
   cvReleaseImage(&img2);
}

2、图像格式:Mat

int main( int argc, char** argv )
{
    Mat img1 = imread("lena.jpg", 1);
    Mat img2(img1.rows,img1.cols,CV_8UC3);
    img1(Rect(10, 15, 150, 250)).copyTo(img2);

    imshow("img1",img1);
    imshow("img2",img2);
    waitKey(0);
}

你可能感兴趣的:(Opencv)