OpenCV实现截图并保存到另外一张图

直接上代码:

#include   
#include   
#include "math.h"
#include   
#include "iostream"
using namespace std;
const char* filename1 = "E:\\projects\\OpenCV\\splitMerge\\splitMerge\\osgEarth.jpg";
int main(int argc, char** argv)
{
	IplImage* img;
	IplImage* img1;
	img = cvLoadImage(filename1, CV_LOAD_IMAGE_COLOR);
	cvNamedWindow("img", CV_WINDOW_AUTOSIZE);
	cvShowImage("img", img);
	CvRect rectInImage;
	rectInImage = cvRect(0, 0, img->width, img->height*0.2);
	CvSize size;
	size.width = rectInImage.width;
	size.height = rectInImage.height;
	img1 = cvCreateImage(size, img->depth, img->nChannels);
	cvSetImageROI(img, rectInImage);//基于给定的矩形设置图像的ROI
	cvCopy(img, img1);
	cvNamedWindow("img1", CV_WINDOW_AUTOSIZE);
	cvShowImage("img1", img1);
	cvResetImageROI(img);
	cvWaitKey(0);
	return 0;
}

效果图:

 

你可能感兴趣的:(OpenCV实现截图并保存到另外一张图)