重映射在图像处理中主要的功能为:将一个图像中一个位置的像素放置到另一个图像指定位置的过程,可以根据自己设定的函数将图像进行变换,较常见的功能有关于x轴翻转,关于y轴翻转,关于x、y轴翻转;仿射变换在图像处理中的主要功能为:对图像进行缩放、旋转、平移、扭曲等。
1、原理
从下面三个链接可以详细的了解到重映射和仿射变换的原理
重映射:http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/imgproc/imgtrans/remap/remap.html#remap
学习OpenCV:http://download.csdn.net/detail/chenjiazhou12/7083295
2、代码实现
程序的功能是:生成两个窗口分别显示重映射的结果和仿射变换的结果
重映射窗口上建立了一个滑动条
0表示:显示原图
1表示:图像宽高缩小一半,并显示在中间
2表示:图像上下颠倒
3表示:图像左右颠倒
4表示:同时执行上下和左右的颠倒
仿射变换窗口建立两个滑动条,一个为缩放功能,一个为旋转功能
旋转的角度为-180—180
缩放因子为:0.1-1.0
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
/// Global variables
Mat src;
Mat warp_dst;
const char* remaptrackbarname="remapvalue";
const char* warprotatetrackbarname="warprotatevalue";
const char* warpscaletrackbarname="warpscalevalue";
const char* remap_window = "Remap demo";
const char* warprotate_window="warprotate demo";
const int remapmaxcount=4,warprotatemaxcount=360,warpscalemaxcount=10;
int remapvalue,warprotatevalue=180, warpscalevalue=10;
/// Function Headers
void update_map( void );
void remapcontrol(int,void*);
void warprotatecontrol(int,void*);
void warpaffinecontrol();
/**
* @function main
*/
int main( int argc, char** argv )
{
/// Load the image
src = imread( "scenery.jpg", 1 );
/// Create dst, map_x and map_y with the same size as src:
/// Create window
namedWindow( remap_window, CV_WINDOW_AUTOSIZE );
namedWindow(warprotate_window,CV_WINDOW_AUTOSIZE);
createTrackbar(remaptrackbarname,remap_window,&remapvalue,remapmaxcount,remapcontrol);
createTrackbar(warprotatetrackbarname,warprotate_window,&warprotat