int RectImage( IplImage* srcImage, cv::CvRect &rect)
{
if (!CV_IS_IMAGE(srcImage))
{
return -1;
}
cvSetImageROI(srcImage, rect);//设置源图像ROI
IplImage* pDest = cvCreateImage(cvSize(rect.width, rect.height), srcImage->depth, srcImage->nChannels);//创建目标图像
cvCopy(srcImage, pDest); //复制图像
cvResetImageROI(srcImage);//源图像用完后,清空ROI 注意:此处是重新设置源图像的ROI区域
cvSaveImage("rectImage.jpg", pDest);
return 0;
}