的OpenCV - 从图像的一格拼接图像 [英] OpenCV - Stitching Images from a grid of images

查看:280
本文介绍了的OpenCV - 从图像的一格拼接图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过OpenCV的发现拼接的一些基本工作实例为全景图像。我还发现一些有用的文档的 API文档 ,但我无法找出如何通过提供额外的信息来加快处理。

在我而言,我产生单个帧的20×20格一组图片,一共有400个图像的被缝合成一个大的。这需要一个现代化的电脑上的大量时间,因此它可能会需要几个小时的开发板。

有没有办法告诉有关图像OpenCV的实例信息,比如我提前知道,因为他们将出现在网格中的所有图像的相对定位是什么?唯一的API调用我看到到目前为止是刚刚乱加的所有图像到一个队列通过 vImg.push_back()


参考


  1. 拼接。图像拼接 - OpenCV的API文档的,访问的2014年2月26日,<一个href=\"http://docs.opencv.org/modules/stitching/doc/stitching.html\"><$c$c><http://docs.opencv.org/modules/stitching/doc/stitching.html>

  2. OpenCV的拼接例如(订书机类,全景)的,访问的2014年2月26日,<一个href=\"http://feelmare.blogspot.ca/2013/11/opencv-stitching-example-stitcher-class.html\"><$c$c><http://feelmare.blogspot.ca/2013/11/opencv-stitching-example-stitcher-class.html>

  3. 全景 - 在OpenCV中的图像拼接,访问的2014年2月26日,<一个href=\"http://ramsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/\"><$c$c><http://ramsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/>


解决方案

据我所知,目前还没有办法提供更多的数据,以OpenCV的发动机不仅仅是给它的图像列表。它本身就是一个pretty好工作虽然。我会检查出一些例子code,并测试每个缝合操作需要多长时间。使用4x6的,4×8,...,的4x20全景重建我的实验中,所需的CPU时间似乎增加重叠的图像的数量。我可以想象你的情况至少需要一分钟来计算一个现代的机器上。

来源:
https://$c$c.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/stitching.cpp?rev=6682

  1 / * M ////////////////////////////////// ////////////////////////////////////////////////// ///
2 //
3 //重要提示:读之前下载,复制,安装或使用。
4 //
5 //通过下载,复制,安装或使用您同意此许可证的软件。
6 //如果您不同意本许可,不下载,安装,
7 //复制或使用该软件。
8 //
9 //
10 //许可协议
11 //开源计算机视觉库
12 //
13 //版权所有(C)2000-2008,英特尔公司,保留所有权利。
14 //版权所有(C)2009,Willow Garage的公司,保留所有权利。
15 //第三方版权均为其各自所有者的财产。
16 //
17 //再分发和使用源代码和二进制形式,无论修改与否,
18 //允许提供的满足以下条件:
19 //
20 // *再分发源$ C ​​$ C的公司必须保留以上版权声明,
21 //此条件列表和下面的免责声明。
22 //
23 // *再分发的二进制格式必须复制上述版权声明,
24 //此条件列表和文档中的下列免责条款
25 //和/或其他在分发提供的材料。
26 //
27 // *版权持有人的名称,不得使用宣传或推销产品
28 //从本软件无需事先书面许可的。
29 //
30 //该软件是由版权所有者和贡献者按原样和
31 //任何Ex preSS或暗示的保证,包括但不限于,暗示
32 //用于特殊目的的适销性和适用性的担保否认。
33 //在任何情况下,英特尔公司贡献者为任何直接,
34 //间接,偶然,特殊,惩戒性,或者后果性损害
35 //(包括但不限于采购替代商品或服务;
36 //使用,数据或利润损失;或业务中断),但造成的
37 //以及任何责任理论,无论是合同,严格责任,
38 //或侵权行为以任何方式所产生的(包括疏忽或其他方式)
39 //使用这个软件,即使被告知此类损害的可能性。
40 //
41 // M * /
42
43 //我们遵循这些论文:
全景马赛克全局和局部比44 // 1)施工。
45 //乡,杨岑和理查德Szeliski。 2000。
46 // 2)消除鬼影和曝光伪影图像拼接。
47 //马修Uyttendaele,阿什利·伊登和理查德Szeliski。 2001年。
48 // 3)自动全景图像使用不变特征拼接。
49 //马修·布朗和戴维·劳。 2007年。
50
51#包括LT&;&iostream的GT;
52#包括LT&;&的fstream GT;
53#包括opencv2 / highgui / highgui.hpp
54#包括opencv2 /拼接/ stitcher.hpp
55
56使用命名空间std;
57使用命名空间的简历;
58
59无效printUsage()
60 {
61 COUT&LT;&LT;
62旋转模型图像拼接。\\ n \\ n
63拼接IMG1 IMG2 [... imgN] \\ n \\ n
64标志:\\ n
65--try_use_gpu(是|否)\\ n
66尝试使用GPU,默认值是'不'。所有的默认值的\\ n
67是CPU模式。\\ n
68--output&LT; result_img&GT; \\ N
69默认为result.jpg的'\\ n;
70}
71
72布尔try_use_gpu = FALSE;
73矢量&lt;&垫GT; IMGS;
74串result_name =result.jpg;
75
76 INT parseCmdArgs(INT ARGC,字符** argv的)
77 {
78,如果(ARGC == 1)
79 {
80 printUsage();
81返回-1;
82}
83(INT I = 1; I&LT; ARGC ++ I)
84 {
85,如果(字符串(的argv [I])==--help||字符串(的argv [I])==/?)
86 {
87 printUsage();
88返回-1;
89}
90如果别人(的字符串(的argv [I])==--try_gpu)
91 {
92,如果(字符串(的argv [I + 1])==不)
93 try_use_gpu = FALSE;
94如果别人(的字符串(的argv [I + 1])==是)
95 try_use_gpu = TRUE;
其他96
97 {
98 COUT&LT;&LT; 坏--try_use_gpu标志值\\ N的;
99返回-1;
100}
101我++;
102}
其他103在(string(的argv [I])==--output)
104 {
105 result_name =的argv [I + 1];
106我++;
107}
其他108
109 {
110席IMG = imread(的argv [I]);
如果111(img.empty())
112 {
113 COUT&LT;&LT; 无法读取图像'&LT;&LT;的argv [1] - ;&LT; '\\ n;
114返回-1;
115}
116 imgs.push_back(IMG);
117}
118}
119返回0;
120}
121
122
123 INT主(INT ARGC,CHAR *的argv [])
124 {
125 INT RETVAL = parseCmdArgs(ARGC,ARGV);
如果126(RETVAL)返回-1;
127
128席全景;
129订书机订书=缝:: createDefault(try_use_gpu);
130缝::状态状态= stitcher.stitch(IMGS,全景);
131
如果132(状态!=缝:: OK)
133 {
134 COUT&LT;&LT; 不能拼接图像,错误code =&LT;&LT;状态&LT;&LT; ENDL;
135返回-1;
136}
137
138 imwrite(result_name,全景);
139返回0;
140}
141
142

I have found some basic working examples on stitching via OpenCV for panoramic images. I have also found some useful documentation in the API docs, but I can't find out how to speed up the processing by providing additional information.

In my case, I generate a set of images in a 20x20 grid of individual frames, for a total of 400 images to be stitched into a single large one. This takes an enormous amount of time on a modern PC, so it would likely take hours on a developer board.

Is there any way to tell the OpenCV instance information about the images, such as me knowing in advance the relative positioning of all the images as they would appear on a grid? The only API calls I see so far is to just add all the images indiscriminately to a queue via vImg.push_back().


References

  1. Stitching. Image Stitching - OpenCV API Documentation, Accessed 2014-02-26, <http://docs.opencv.org/modules/stitching/doc/stitching.html>
  2. OpenCV Stitching example (Stitcher class, Panorama), Accessed 2014-02-26, <http://feelmare.blogspot.ca/2013/11/opencv-stitching-example-stitcher-class.html>
  3. Panorama – Image Stitching in OpenCV, Accessed 2014-02-26, <http://ramsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/>

解决方案

So far as I know, there is no means to provide additional data to the OpenCV engine beyond just giving it a list of images. It does a pretty good job on its own though. I would check out some of the example code, and test how long each stitching operation takes. From my experiments using 4x6, 4x8, ..., 4x20 panoramic reconstructions, the CPU time required seems to increase with the number of overlapping images. I would imagine your case would require at least a minute to compute on a modern machine.

Source: https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/stitching.cpp?rev=6682

1   /*M///////////////////////////////////////////////////////////////////////////////////////
2   //
3   //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4   //
5   //  By downloading, copying, installing or using the software you agree to this license.
6   //  If you do not agree to this license, do not download, install,
7   //  copy or use the software.
8   //
9   //
10  //                          License Agreement
11  //                For Open Source Computer Vision Library
12  //
13  // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14  // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15  // Third party copyrights are property of their respective owners.
16  //
17  // Redistribution and use in source and binary forms, with or without modification,
18  // are permitted provided that the following conditions are met:
19  //
20  //   * Redistribution's of source code must retain the above copyright notice,
21  //     this list of conditions and the following disclaimer.
22  //
23  //   * Redistribution's in binary form must reproduce the above copyright notice,
24  //     this list of conditions and the following disclaimer in the documentation
25  //     and/or other materials provided with the distribution.
26  //
27  //   * The name of the copyright holders may not be used to endorse or promote products
28  //     derived from this software without specific prior written permission.
29  //
30  // This software is provided by the copyright holders and contributors "as is" and
31  // any express or implied warranties, including, but not limited to, the implied
32  // warranties of merchantability and fitness for a particular purpose are disclaimed.
33  // In no event shall the Intel Corporation or contributors be liable for any direct,
34  // indirect, incidental, special, exemplary, or consequential damages
35  // (including, but not limited to, procurement of substitute goods or services;
36  // loss of use, data, or profits; or business interruption) however caused
37  // and on any theory of liability, whether in contract, strict liability,
38  // or tort (including negligence or otherwise) arising in any way out of
39  // the use of this software, even if advised of the possibility of such damage.
40  //
41  //M*/
42  
43  // We follow to these papers:
44  // 1) Construction of panoramic mosaics with global and local alignment.
45  //    Heung-Yeung Shum and Richard Szeliski. 2000.
46  // 2) Eliminating Ghosting and Exposure Artifacts in Image Mosaics.
47  //    Matthew Uyttendaele, Ashley Eden and Richard Szeliski. 2001.
48  // 3) Automatic Panoramic Image Stitching using Invariant Features.
49  //    Matthew Brown and David G. Lowe. 2007.
50  
51  #include <iostream>
52  #include <fstream>
53  #include "opencv2/highgui/highgui.hpp"
54  #include "opencv2/stitching/stitcher.hpp"
55  
56  using namespace std;
57  using namespace cv;
58  
59  void printUsage()
60  {
61      cout <<
62          "Rotation model images stitcher.\n\n"
63          "stitching img1 img2 [...imgN]\n\n"
64          "Flags:\n"
65          "  --try_use_gpu (yes|no)\n"
66          "      Try to use GPU. The default value is 'no'. All default values\n"
67          "      are for CPU mode.\n"
68          "  --output <result_img>\n"
69          "      The default is 'result.jpg'.\n";
70  }
71  
72  bool try_use_gpu = false;
73  vector<Mat> imgs;
74  string result_name = "result.jpg";
75  
76  int parseCmdArgs(int argc, char** argv)
77  {
78      if (argc == 1)
79      {
80          printUsage();
81          return -1;
82      }
83      for (int i = 1; i < argc; ++i)
84      {
85          if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
86          {
87              printUsage();
88              return -1;
89          }
90          else if (string(argv[i]) == "--try_gpu")
91          {
92              if (string(argv[i + 1]) == "no")
93                  try_use_gpu = false;
94              else if (string(argv[i + 1]) == "yes")
95                  try_use_gpu = true;
96              else
97              {
98                  cout << "Bad --try_use_gpu flag value\n";
99                  return -1;
100             }
101             i++;
102         }
103         else if (string(argv[i]) == "--output")
104         {
105             result_name = argv[i + 1];
106             i++;
107         }
108         else
109         {
110             Mat img = imread(argv[i]);
111             if (img.empty())
112             {
113                 cout << "Can't read image '" << argv[i] << "'\n";
114                 return -1;
115             }
116             imgs.push_back(img);
117         }
118     }
119     return 0;
120 }
121 
122 
123 int main(int argc, char* argv[])
124 {
125     int retval = parseCmdArgs(argc, argv);
126     if (retval) return -1;
127 
128     Mat pano;
129     Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
130     Stitcher::Status status = stitcher.stitch(imgs, pano);
131 
132     if (status != Stitcher::OK)
133     {
134         cout << "Can't stitch images, error code = " << status << endl;
135         return -1;
136     }
137 
138     imwrite(result_name, pano);
139     return 0;
140 }
141 
142 

这篇关于的OpenCV - 从图像的一格拼接图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆