本来呢我是不想写这篇博客的,可是!看到别人写的很气。
就比如https://www.jianshu.com/p/4307c31368ff。这里面图像平铺能实现的了?开玩笑,而且一个人这么写也就算了,一堆人跟着抄,抄也就算了,好歹自己也验证下啊。不验证就直接抄。
不多逼逼,上我的代码
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv)
{
Mat img1;
namedWindow("Example1", WINDOW_AUTOSIZE);
img1 = imread(argv[1]);
int rows = 0;
int cols = 0;
int new_rows = 5000;
int new_cols = 5000;
Mat img2;
img2.create(new_rows, new_cols, img1.type());
for (int i = 0; i < new_rows; i++)
{
if (rows < img1.rows)
{
for (int j = 0; j < new_cols; j++)
{
if (cols < img1.cols)
{
img2.at<Vec3b>(i, j)[0] = img1.at<Vec3b>(rows, cols)[0];
img2.at<Vec3b>(i, j)[1] = img1.at<Vec3b>(rows, cols)[1];
img2.at<Vec3b>(i, j)[2] = img1.at<Vec3b>(rows, cols)[2];
cols += 1;
}
else
{
cols = 0;
}
}
rows += 1;
cols = 0;//重要的是这里,一定要归零
}
else
{
rows = 0;
}
}
imwrite("4c.jpg", img2);
imshow("Example1", img2);
cv::waitKey(0);
destroyAllWindows();
return 0;
}