资源简介
全景拼接c++代码
代码片段和文件信息
#include “stdafx.h“
#include “Blend.h“
#include
#include
bool isEmpty(const CImg &img int x int y) {
assert(img.spectrum() == 3);
return (img(x y 0) == 0 && img(x y 1) == 0 && img(x y 2) == 0);
}
CImg blendTwoImages(const CImg &a const CImg &b) {
assert(a.width() == b.width() && a.height() == b.height() && a.spectrum() == b.spectrum());
// Find the center point of a and overlapping part.
double sum_a_x = 0;
double sum_a_y = 0;
int a_n = 0;
//double sum_b_x = 0;
//double sum_b_y = 0;
//int b_n = 0;
double sum_overlap_x = 0;
double sum_overlap_y = 0;
int overlap_n = 0;
if (a.width() > a.height()) {
for (int x = 0; x < a.width(); x++) {
if (!isEmpty(a x a.height() / 2)) {
sum_a_x += x;
a_n++;
}
//if (!isEmpty(b x b.height() / 2)) {
// sum_b_x += x;
// b_n++;
//}
if (!isEmpty(a x a.height() / 2) && !isEmpty(b x a.height() / 2)) {
sum_overlap_x += x;
overlap_n++;
}
}
}
else {
for (int y = 0; y < a.height(); y++) {
if (!isEmpty(a a.width() / 2 y)) {
sum_a_y += y;
a_n++;
}
if (!isEmpty(a a.width() / 2 y) && !isEmpty(b b.width() / 2 y)) {
sum_overlap_y += y;
overlap_n++;
}
}
}
int min_len = (a.width() < a.height()) ? a.width() : a.height();
int n_level = floor(log2(min_len));
vector > a_pyramid(n_level);
vector > b_pyramid(n_level);
vector > mask(n_level);
// Initialize the base.
a_pyramid[0] = a;
b_pyramid[0] = b;
mask[0] = CImg(a.width() a.height() 1 1 0);
if (a.width() > a.height()) {
if (sum_a_x / a_n < sum_overlap_x / overlap_n) {
for (int x = 0; x < sum_overlap_x / overlap_n; x++) {
for (int y = 0; y < a.height(); y++) {
mask[0](x y) = 1;
}
}
}
else {
for (int x = sum_overlap_x / overlap_n + 1; x < a.width(); x++) {
for (int y = 0; y < a.height(); y++) {
mask[0](x y) = 1;
}
}
}
}
else {
if (sum_a_y / a_n < sum_overlap_y / overlap_n) {
for (int x = 0; x < a.width(); x++) {
for (int y = 0; y < sum_overlap_y / overlap_n; y++) {
mask[0](x y) = 1;
}
}
}
else {
for (int x = 0; x < a.width(); x++) {
for (int y = sum_overlap_y / overlap_n; y < a.height(); y++) {
mask[0](x y) = 1;
}
}
}
}
// Down sampling a and b building Gaussian pyramids.
for (int i = 1; i < n_level; i++) {
a_pyramid[i] = a_pyramid[i - 1].get_blur(2).get_resize(a_pyramid[i - 1].width() / 2 a_pyramid[i - 1].height() / 2 1 a_pyramid[i - 1].spectrum() 3);
b_pyramid[i] = b_pyramid[i - 1].get_blur(2).get_resize(b_pyramid[i - 1].width() / 2 b_pyramid[i - 1].height() / 2 1 b_pyramid[i - 1].spectrum() 3);
mask[i] = mask[i - 1].get_blur(2).get_resize(mask[i - 1].width() / 2 mask[i - 1].height() / 2 1 mask[i - 1].spectrum() 3);
}
// Building Laplacian pyramids.
for (int i = 0; i < n_level - 1; i++) {
a_pyramid[i]
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 2518 2016-06-22 05:10 ImageStitching-master\.gitattributes
....... 2806 2016-06-22 05:10 ImageStitching-master\.gitignore
..A..H. 90624 2017-04-25 11:10 ImageStitching-master\.vs\ImageStitching\v14\.suo
文件 2295808 2017-01-16 11:13 ImageStitching-master\Debug\ImageStitching.exe
文件 2286756 2017-01-16 11:13 ImageStitching-master\Debug\ImageStitching.ilk
文件 5648384 2017-01-16 11:13 ImageStitching-master\Debug\ImageStitching.pdb
文件 4335 2017-01-13 16:17 ImageStitching-master\ImageStitching\Blend.cpp
文件 273 2017-01-16 10:37 ImageStitching-master\ImageStitching\Blend.h
....... 2692205 2016-06-22 05:10 ImageStitching-master\ImageStitching\CImg.h
....... 589878 2016-06-22 05:10 ImageStitching-master\ImageStitching\dataset1\1.bmp
....... 589878 2016-06-22 05:10 ImageStitching-master\ImageStitching\dataset1\2.bmp
....... 589878 2016-06-22 05:10 ImageStitching-master\ImageStitching\dataset1\3.bmp
....... 589878 2016-06-22 05:10 ImageStitching-master\ImageStitching\dataset1\4.bmp
文件 589878 2017-01-16 10:46 ImageStitching-master\ImageStitching\dataset2\1.bmp
文件 589878 2017-01-16 10:48 ImageStitching-master\ImageStitching\dataset2\10.bmp
文件 589878 2017-01-16 10:48 ImageStitching-master\ImageStitching\dataset2\11.bmp
文件 589878 2017-01-16 10:48 ImageStitching-master\ImageStitching\dataset2\12.bmp
文件 589878 2017-01-16 10:48 ImageStitching-master\ImageStitching\dataset2\13.bmp
文件 589878 2017-01-16 10:49 ImageStitching-master\ImageStitching\dataset2\14.bmp
文件 589878 2017-01-16 10:49 ImageStitching-master\ImageStitching\dataset2\15.bmp
文件 589878 2017-01-16 10:49 ImageStitching-master\ImageStitching\dataset2\16.bmp
文件 589878 2017-01-16 10:49 ImageStitching-master\ImageStitching\dataset2\17.bmp
文件 589878 2017-01-16 10:49 ImageStitching-master\ImageStitching\dataset2\18.bmp
文件 589878 2017-01-16 10:46 ImageStitching-master\ImageStitching\dataset2\2.bmp
文件 589878 2017-01-16 10:46 ImageStitching-master\ImageStitching\dataset2\3.bmp
文件 589878 2017-01-16 10:46 ImageStitching-master\ImageStitching\dataset2\4.bmp
文件 589878 2017-01-16 10:46 ImageStitching-master\ImageStitching\dataset2\5.bmp
文件 589878 2017-01-16 10:47 ImageStitching-master\ImageStitching\dataset2\6.bmp
文件 589878 2017-01-16 10:47 ImageStitching-master\ImageStitching\dataset2\7.bmp
文件 589878 2017-01-16 10:47 ImageStitching-master\ImageStitching\dataset2\8.bmp
............此处省略391个文件信息
评论
共有 条评论