规则图像拼接

/*
Author: Duyang
Data:   2018.10.25
Object: to practice the function that connects patch images into a whole image
*/
# include <opencv2/opencv.hpp>
# include <iostream>
# include <string>
# include <sstream>
# include <time.h>
using namespace std;
using namespace cv;
enum {
	patch_image_row = 608, patch_image_col = 608, \
	connection_image_row = 6080, connection_image_col = 7904
};
string image_path = "C:\\Users\\Yang\\Desktop\\实验数据\\深度学习成果\\convnet5x5\\图2-1\\二值\\";
string int_to_str;
void int2string(int & int_temp, string & str_temp)
{
	stringstream convert;
	convert << int_temp;
	convert >> str_temp;//this sentence equivalent to: str_temp = conver.str()
}
int main()
{

	clock_t start = clock();
	Mat merging_image(connection_image_row, connection_image_col, CV_8UC1);
	int count = 0;
	for (int i = 0; i < connection_image_row / patch_image_row; i++)
	{
		for (int j = 0; j < connection_image_col / patch_image_col; j++)
		{
			
			printf("%d\n", count);
			int2string(count, int_to_str);
			count++;
			Mat patch_image = imread(image_path + "(" + int_to_str + ").png",0);
			for (int m = 0; m < patch_image_row; m++)
			{
				uchar *p = merging_image.ptr<uchar>(m + i * patch_image_row);
				uchar  *p1 = patch_image.ptr<uchar>(m);
				for (int n = 0; n < patch_image_col; n++)
				{
				
					*(p + n + j * patch_image_col) = *(p1 + n);
				
				}
			}
		}
	}
	imwrite("merging.png", merging_image);
	clock_t finish = clock();
	double consumeTime = (double)(finish - start) / CLOCKS_PER_SEC;
	printf("%f", consumeTime);//83.571000

	getchar();
	return 0;
}



/*
summary: sprintf()
*/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嘟嘟love佳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值