#include<opencv2\highgui\highgui.hpp>
#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
char *output_title = "output Image";
Mat src, dst, map_x, map_y;
int index = 0;
void update_map(void);
//霍夫圆检测前先进行中值滤波
int main()
{
src = imread("E:\\vs2015\\opencvstudy\\1.jpg", 1);
if (src.empty())
{
cout << "could not load the src image!" << endl;
return -1;
}
char *input_title = "input Image";
imshow(input_title, src);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
map_x.create(src.size(), CV_32FC1);
map_y.create(src.size(), CV_32FC1);
int c = 0;
while (true)
{
c = waitKey(500);
if ((char)c == 27)
{
break;
}
cout << "c:" << c << endl;
index = c % 4;
cout << "index"<<index << endl;
update_map();
remap(src, dst, map_x, map_y, INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 255, 255));
imshow(output_title, dst);
}
//waitKey(0);
return 0;
}
void update_map(void) {
for (int row = 0; row < src.rows; row++)
{
for (int col = 0; col < src.cols; col++)
{
switch (index)
{
case 0:
if (col > (src.cols*0.25) && col<(src.cols*0.75) && row>(src.rows*0.25) && row < (src.rows*0.75))
{
map_x.at<float>(row, col) = 2 * (col - (src.cols*0.25));
map_y.at<float>(row, col) = 2 * (row - (src.rows*0.25));
}
else {
map_x.at<float>(row, col) = 0;
map_y.at<float>(row, col) = 0;
}
break;
case 1:
map_x.at<float>(row, col) = src.cols - col - 1;
map_y.at<float>(row, col) = row;
break;
case 2:
map_x.at<float>(row, col) = col;
map_y.at<float>(row, col) = src.rows - row - 1;
break;
case 3:
map_x.at<float>(row, col) = src.cols - col - 1;
map_y.at<float>(row, col) = src.rows - row - 1;
break;
}
}
}
}