由于最近在学习超分辨率算法,但是大多数开源程序输入图片太大就显示显存不够,因此就把手机拍摄的图片先分割成一系列小的图片,超分辨率之后再拼接在一块
OpenCV的程序如下:比较简单,对5x5即25张图片进行拼接:
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
int i = 0,j=0;
Mat combine;
Mat row[5][5], column[5];
Mat com_row[5][5], con_column[5];
row[0][0] = imread("C:\\test\\pic_div\\1-1.jpg");
row[0][1] = imread("C:\\test\\pic_div\\1-2.jpg");
row[0][2] = imread("C:\\test\\pic_div\\1-3.jpg");
row[0][3] = imread("C:\\test\\pic_div\\1-4.jpg");
row[0][4] = imread("C:\\test\\pic_div\\1-5.jpg");
row[1][0] = imread("C:\\test\\pic_div\\2-1.jpg");
row[1][1] = imread("C:\\test\\pic_div\\2-2.jpg");
row[1][2] = imread("C:\\test\\pic_div\\2-3.jpg");
row[1][3] = imread("C:\\test\\pic_div\\2-4.jpg");
row[1][4] = imread("C:\\test\\pic_div\\2-5.jpg");
row[2][0] = imread("C:\\test\\pic_div\\3-1.jpg");
row[2][1] = imread("C:\\test\\pic_div\\3-2.jpg");
row[2][2] = imread("C:\\test\\pic_div\\3-3.jpg");
row[2][3] = imread("C:\\test\\pic_div\\3-4.jpg");
row[2][4] = imread("C:\\test\\pic_div\\3-5.jpg");
row[3][0] = imread("C:\\test\\pic_div\\4-1.jpg");
row[3][1] = imread("C:\\test\\pic_div\\4-2.jpg");
row[3][2] = imread("C:\\test\\pic_div\\4-3.jpg");
row[3][3] = imread("C:\\test\\pic_div\\4-4.jpg");
row[3][4] = imread("C:\\test\\pic_div\\4-5.jpg");
row[4][0] = imread("C:\\test\\pic_div\\5-1.jpg");
row[4][1] = imread("C:\\test\\pic_div\\5-2.jpg");
row[4][2] = imread("C:\\test\\pic_div\\5-3.jpg");
row[4][3] = imread("C:\\test\\pic_div\\5-4.jpg");
row[4][4] = imread("C:\\test\\pic_div\\5-5.jpg");
//cv::resize(a, a, cv::Size(1984, 1488), 0, 0, CV_INTER_LINEAR);
//cv::resize(b, b, cv::Size(1984, 1488), 0, 0, CV_INTER_LINEAR);
//cv::resize(c, c, cv::Size(1984, 1488), 0, 0, CV_INTER_LINEAR);
//cv::resize(d, d, cv::Size(1984, 1488), 0, 0, CV_INTER_LINEAR);
//水平拼接
com_row[0][0] = row[0][0];
com_row[1][0] = row[1][0];
com_row[2][0] = row[2][0];
com_row[3][0] = row[3][0];
com_row[4][0] = row[4][0];
for (i = 0; i < 5; i = i + 1)
{
for (j = 0; j < 4; j = j + 1)
{
hconcat(com_row[i][j], row[i][j+1], com_row[i][j+1]);
}
column[i] = com_row[i][4]; //产生的每一行的拼接图片
}
//垂直拼接
con_column[0] = column[0];
for (i = 0; i < 4; i = i + 1)
{
vconcat(con_column[i], column[i + 1], con_column[i + 1]);
}
combine = con_column[4];
namedWindow("Combine", CV_WINDOW_AUTOSIZE);
imshow("Combine", combine);
imwrite("Combine.png", combine);
cv::waitKey(1);
system("pause");
return 0;
}
拼接 之前的图片:
拼接之后: