我正在使用Visual Studio 2012,C中的多图像拼接.我根据我的要求修改了

stitching_detailed.cpp,它给出了高质量的结果.这里的问题是,执行需要太多时间.对于10张图像,大约需要110秒.

这是大部分时间所需的地方:

1)成对匹配 – 10张图像需要55秒!我正在使用ORB来查找特征点.这是代码:

vector pairwise_matches;
BestOf2NearestMatcher matcher(false,0.35);
matcher(features,pairwise_matches);
matcher.collectGarbage();

我尝试使用此代码,因为我已经知道图像序列:

vector pairwise_matches;
BestOf2NearestMatcher matcher(false,0.35);
Mat matchMask(features.size(),features.size(),CV_8U,Scalar(0));
for (int i = 0; i < num_images -1; ++i)
matchMask.at(i,i+1) =1;
matcher(features,pairwise_matches,matchMask);
matcher.collectGarbage();

它肯定会减少时间(18秒),但不会产生所需的结果.只有6个图像被拼接(最后4个被遗漏,因为图像6和图像7的特征点在某种程度上不匹配.所以循环中断了.)

2)合成 – 10张图片需要38秒!这是代码:

for (int img_idx = 0; img_idx < num_images; ++img_idx)
{
printf("Compositing image #%d\n",indices[img_idx]+1);
// Read image and resize it if necessary
full_img = imread(img_names[img_idx]);
Mat K;
cameras[img_idx].K().convertTo(K,CV_32F);
// Warp the current image
warper->warp(full_img,K,cameras[img_idx].R,INTER_LINEAR,BORDER_REFLECT,img_warped);
// Warp the current image mask
mask.create(full_img.size(),CV_8U);
mask.setTo(Scalar::all(255));
warper->warp(mask,INTER_NEAREST,BORDER_CONSTANT,mask_warped);
// Compensate exposure
compensator->apply(img_idx,corners[img_idx],img_warped,mask_warped);
img_warped.convertTo(img_warped_s,CV_16S);
img_warped.release();
full_img.release();
mask.release();
dilate(masks_warped[img_idx],dilated_mask,Mat());
resize(dilated_mask,seam_mask,mask_warped.size());
mask_warped = seam_mask & mask_warped;
// Blend the current image
blender->feed(img_warped_s,mask_warped,corners[img_idx]);
}
Mat result,result_mask;
blender->blend(result,result_mask);

原始图像分辨率为4160 * 3120.我没有在合成中使用压缩,因为它降低了质量.我在其余的代码中使用了压缩图像.

正如您所看到的,我修改了代码并减少了时间.但我仍然希望尽可能减少时间.

3)查找特征点 – 使用ORB. 10张图片需要10秒钟.为图像找到1530个最大特征点.

55 38 10 = 103 7其余代码= 110.

当我在android中使用这个代码时,它需要几乎整个智能手机的内存(RAM)才能执行.如何减少Android设备的时间和内存消耗? (我使用的Android设备有2 GB RAM)

我已经优化了其余的代码.任何帮助深表感谢!

编辑1:我在合成步骤中使用了图像压缩,时间从38秒减少到16秒.我还设法减少了其余代码的时间.

所以现在,从110 – > 85秒帮助我减少成对匹配的时间;我不知道减少它!

编辑2:我在matchers.cpp中找到了成对匹配的代码.我在主代码中创建了自己的函数来优化时间.对于合成步骤,我使用压缩直到最终图像不会失去清晰度.对于特征查找,我使用图像缩放以缩小的图像比例查找图像特征.现在我可以轻松缝合多达50张图像.