#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<stdio.h>
using namespace cv;
void pingyi(Mat img, Mat &dst, int x, int y);
int main() {
Mat img = imread("H:\\city.jpg");
Mat dst = img.clone();
namedWindow("001", 500);
namedWindow("002", 500);
int x, y;
printf("输入x:");
scanf("%d", &x);
printf("输入y:");
scanf("%d", &y);
pingyi(img, dst, x, y);
imshow("001", img);
imshow("002", dst);
waitKey(0);
return 0;
}
void pingyi(Mat img, Mat &dst, int x, int y) {
int maxrows = img.rows;
int maxcols = img.cols;
for (int i = 0; i < maxrows; i++) {
for (int j = 0; j < maxcols; j++) {
if (i - x > 0 && i - x < maxrows&&j - y>0 && j - y < maxcols) {
dst.at<Vec3b>(i, j) = img.at<Vec3b>(i - x, j - y);
}
else {
dst.at<Vec3b>(i, j)[0] = 0;
dst.at<Vec3b>(i, j)[1] = 0;
dst.at<Vec3b>(i, j)[2] = 0;
}
}
}
}