opencv4 图像平铺实现

本来呢我是不想写这篇博客的,可是!看到别人写的很气。

就比如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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值