/*
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()
*/