OpenCV学习(十五)之图像金字塔

实验环境:VS2010 + OpenCV2.4.9.0

#include <iostream>
#include "cv.h"
#include <highgui.h>

using namespace std;
using namespace cv;

int main(int argc,char*argv[])
{
	char* wndName = "Pyramids Demo";
	Mat img = imread("lena.jpg");
	if(!img.data)
	{
		cerr <<"No Data!" << endl;
		exit(1);
	}
	Mat tmp = img.clone();
	Mat dst = tmp;
	namedWindow(wndName,CV_WINDOW_AUTOSIZE);
	imshow(wndName,dst);

	while(TRUE)
	{
		char c;
		c = waitKey(10);
		if(c == 27)
		{
			break;
		}
		if(c == 'u')
		{
			pyrUp(tmp,dst,Size(tmp.cols * 2,tmp.rows * 2));
			cout << "Zoom In: x2" <<endl;
		}
		else if(c == 'd')
		{
			pyrDown(tmp,dst,Size(tmp.cols/2,tmp.rows/2));
			cout << "Zoom Out: /2" << endl;
		}
		imshow(wndName,dst);
		tmp = dst;
	}
	return 1;
}
实验结果:

原图:

OpenCV学习(十五)之图像金字塔_第1张图片


两倍:(实际不是两倍,图片太大不能上传)

OpenCV学习(十五)之图像金字塔_第2张图片


小两倍:

OpenCV学习(十五)之图像金字塔_第3张图片


参考文献:

http://baike.baidu.com/link?url=MjU9EooCucwD-lWqJ_Brq4Hjt7hKszzEGP8AEFIu4rlBwKllkrYcNDZLZi2jJPlBtBlfIr-xN0XVkF1Ozum9Oa

http://docs.opencv.org/doc/tutorials/imgproc/pyramids/pyramids.html

链接一篇使用旧版本的例子:

http://blog.csdn.net/hitwengqi/article/details/6857441



你可能感兴趣的:(图像金字塔,OpenCV学习)