OpenCV数字图像处理六:图像垂直翻转

/*OpenCV2.4.3*/


#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, dst;


Mat map_x, map_y;


char* remap_window = "RotateImage";


int ind = 0;


/// Function Headers
void update_map( void );


int main( int argc, char** argv )
{
/// Load the image
src = imread("test.jpg");


/// Create dst, map_x and map_y with the same size as src:
dst.create( src.size(), src.type() );
map_x.create( src.size(), CV_32FC1 );
map_y.create( src.size(), CV_32FC1 );


/// Create window
namedWindow( remap_window, CV_WINDOW_AUTOSIZE );


/// Update map_x & map_y. Then apply remap
for( int j = 0; j < src.rows; j++ ){ 
for( int i = 0; i < src.cols; i++ ){
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = src.rows - j ;
}
}


remap( src, dst, map_x, map_y, CV_INTER_LINEAR, BORDER_CONSTANT, Scalar(0,0, 0) );


/// Display results
imshow( remap_window, dst );
imwrite("rotateImage.jpg",dst);
cv::waitKey(0);
return 0;
}

你可能感兴趣的:(OpenCV数字图像处理六:图像垂直翻转)