天天看點

Bundler 使用者指南

copyright 2008-2009 Noah Snavely ([email protected])        
any problems : please e-mail [email protected]      
什麼是Bundler?      
Bundler是主要用于無序圖檔(源于搜尋引擎的圖檔)收集的運動估計結構的系統。Bundler以一組圖檔、圖檔特征、圖像之間的比對關系作為輸入,以此重建相機的3D位置和場景的稀疏結構。系統使用遞增的方式重建場景,每次處理幾幅圖檔,使用了Lourakis and Argyros的Sparse Bundler Adjustment資料包的改進版本作為優化方式(主要用疊代的方法來減少在投影中可能存在的誤差)。本Blog的前幾個文章介紹了兩種在Windows環境下安裝Bundler的方法。(在CYGWIN平台上使用Bundler,VS2010下Bundler的使用)      
Bundler軟體包中都有什麼?      
和Bundler的二進制代碼在一起的是Bundler的可執行檔案(bin/bundler)和一些其他可用的腳本和可執行檔案(bin/directory)。此外,在目錄examples/directory下有圖檔集和例子的結果。還有David M.Mount和Sunil Arya的ANN(approximate nearest neighbors)庫,用來搜尋無符号向量。      
一個實用的功能将輸出的Bundle檔案(.out)轉換成Dr. Yasutaka Furukawa's開發的PMVS多視點立體系統所利用的檔案Bundle2PMVS檔案也被包含在程式中。有一個被稱作RadialUndistort的能産生不失真的檔案也被包含在程式中。      
最後還有能讀取EXIF的jhead程式也被包含在程式中。(相關解釋可以檢視本Blog中的利用照片攜帶的EXIF來估計焦距等資訊)。      
在開始使用Bundler之前      
本Blog的前幾個文章介紹了兩種在Windows環境下安裝Bundler的方法。(在CYGWIN平台上使用Bundler,VS2010下Bundler的使用)      
首先可以下載下傳Bundler檔案:http://phototour.cs.washington.edu/bundler/,并将下載下傳的檔案解壓在某一路徑之下(BASE_PATH),可能還需要ImageMagick(http://www.imagemagick.org/)将jpg轉換成pgm,以便能使用SIFT(http://www.cs.ubc.ca/~lowe/keypoints/),将SIFT檔案拷貝到路徑BASE_PATH/bin之下(確定是'sift',或在Windows平台上選擇 'siftWin32.exe' ). RunBundler.sh的産生依賴于Bash編譯器和Prel編輯器。最簡單的使用方法是用cygwin。最後将BASE_PATH/lib/libANN_char.so中的ANN共享庫拷貝到LD_LIBRARY_PATH (or add BASE_PATH/lib to LD_LIBRARY_PATH).      
運作Bundler      
最簡單的運作Bundler的方法是使用Bash Shell腳本 RunBundler.sh 簡單地在帶有一系列JPEG格式圖檔的檔案路徑之下執行腳本,它會自動地完成所有從運動恢複結構的所有操作。像上文提到的那樣,需要先編輯腳本并确定BASE_PATH變量的值。(還需要編輯Perl腳本BASE_PATH/bin/extract_focal.pl中的BASE_PATH變量和Bash腳本 BASE_PATH/bin/ToSift.sh)。      
Bundler的執行是這一系列重建場景操作的最後一步。RunBundler.sh幫我們處理了所有的操作,但知道如何去做是十分必要的。主要的初始化操作是産生特征點和圖檔集的成對特征點的比對。雖然特征值檢測可以用任意算法,但是由于Bundler設計時是圍繞SIFT展開的,是以建議使用SIFT。估計焦距的過程也應該被指定。重建操作可以分為以下四步:      
1. 利用腳本‘extract_focal.pl’建立圖像清單,同時提取了焦距資訊,并存儲在檔案清單之中。      
2. 為每幅圖像建立SIFT特征資訊。      
3. 針對每對圖像做特征比對,将計算出的比對存儲在檔案‘matchs.init.txt’中。      
4. 在特定的選項之下運作Bundler。      
執行RunBundler.sh腳本是執行上述操作的最簡單方法。為了簡化1-3步驟,很多可用的腳本和程式都調用這個軟體。      
Bundler自身最典型的調用方法如下:      
   > bundler list.txt --options_file options.txt      
第一項是将被重建的圖檔清單,下面是給出指定選項操作的選項檔案。RunBundler.sh能建立相應的選項檔案并工作在多個場合之中。通用操作在後續中描述。      
輸出檔案格式與場景表達      
Bundler生成的檔案名‘bundle_*.out’。使用預設的指令,Bundler生成的檔案名為‘bundle_<n>.out’,在每組圖檔被寄存之後,它包含了目前場景的狀态(n = 目前寄存相機的數目)。所有可能的圖檔都被寄存之後,Bundler 輸出最後的檔案‘bundle.out’.另外,‘ply’檔案包含了在每次循環之後的重建的相機與重建的點。這些ply檔案中可以利用“scanalyze”mesh viewer(http://graphics.stanford.edu/software/scanalyze/)或Meshlab(http://meshlab.sourceforge.net/)。      
bundle 檔案中包含了估計的場景和相機的幾何結構:      
# Bundle file v0.3
    <num_cameras> <num_points>   [two integers]
    <camera1>
    <camera2>
       ...
    <cameraN>
    <point1>
    <point2>
       ...
    <pointM>      
每個相機項目<camerai>都包含估計相機的内部矩陣和外部矩陣,具有如下的格式:(相機全零的位置在點雲的資料上沒有選取)      
<f> <k1> <k2>   [the focal length, followed by two radial distortion coeffs]
    <R>             [a 3x3 matrix representing the camera rotation]
    <t>             [a 3-vector describing the camera translation]      
相機出現的次序與圖檔清單相一緻。      
每個點的表示都有如下的形式:      
<position>      [a 3-vector describing the 3D position of the point]
    <color>         [a 3-vector describing the RGB color of the point]
    <view list>     [a list of views the point is visible in]      
每個 view list 以 list 的長度為起始(i.e., the number of cameras the point is visible in).這個清單是以四元的形式表述的:<camera> <key> <x> <y>。這裡的<camera>表示相機的引索值,<key>表示的是在相應的相機中SIFT的引索值,<x>、<y>是相應關鍵點的位置坐标。所有的引索值都是從0開始的。像素點的位置是用浮點型表示,坐标原點在圖像的中心。x軸向右增加,y軸向上增加。是以(-w/2, -h/2)表示的是圖像的左下角,(w/2, h/2)表示的是圖像空間的右上角。      
我們使用了一個針孔相機模型,我們估計的參數有:焦距f,兩個射線失真系數k1、k2,旋轉矩陣R,平移t。将3D點投影在相機(R, t, f)可以有如下表示:      
P = R * X +  t  (conversion from world to camera coordinates)      
p = -P / P.z  (perspective division)      
p' = f * r(p) *p  (conversion to pixel coordinates)      
這裡的P.z是P坐标的第三維坐标z。最下面的等式中的r(p)是計算放縮因子去除radial失真:      
r(p) = 1.0 + k1 * || p ||^2 + k2 * || p ||^4.      
這個表達式給出了在像素點上的投影,圖檔的原點在圖像的中心(in addition, in the camera coordinate system, the positive z-axis points backwards, so the camera is looking down the negative z-axis, as in OpenGL).      
最後,上面描述的這些等式的觀測方向為:R' * [0 0 -1]'  (i.e., the third row of -R or third column of -R')      
(where ' indicates the transpose of a matrix or vector).      
相機的3D位置可以表述成:-R' * t.      
指令行選項      
Bundler有一組内部參數,是以這裡有大量的指令行選項。通過實驗測試已經獲得了一組參數,能夠應對大多數的圖檔收集過程,是以利用預設的參數也是可靠的(使用RunBundler.sh腳本)。使用'--options_file <file>'的選項也是很可靠的,它告訴Bundler去從檔案之中讀取一組選項清單。由RunBundler.sh建立的預設選項檔案表示如下:      
--match_table matches.init.txt
     [specifies the file where the match files are stored]比對關系的存儲位置

  --output bundle.out
     [specifies the name of the final output reconstruction]輸出的檔案名

  --output_all bundle_
     [specifies that all intermediate reconstructions should be重建的中間結果的檔案名
      output to files with prefix "bundle_"]

  --output_dir bundle
     [the directory all output files should be written to, typically輸出檔案的所在路徑
      called "bundle"]

  --variable_focal_length
     [directs bundler to optimize for an independent focal length for每幅圖檔獨立焦距值的最優解
      each image]

  --use_focal_estimate
     [directs bundler to use the estimated focal lengths obtained from在EXIF檔案中獲得的估計焦距值
      the Exif tags for each image]

  --constrain_focal
     [constrain the focal length of each camera to be close to the增加了焦距的限制
      initial focal length estimate (from Exif tags).  This option
      adds penalty terms to the bundle adjustment objective function]

  --constrain_focal_weight 0.0001
     [weight on the penalty terms for the focal length constraints (a
      small weight is typically sufficient)]

  --estimate_distortion
     [directs bundler to estimate radial distortion parameters for指定radial失真系數
      each image]

  --run_bundle
     [run structure from motion (as opposed to other operations on
      existing reconstructions)]      
其他選型:      
除了預設的選項,下列的選型也十分重要,包括:      
--init_pair1 <image_idx1>
  --init_pair2 <image_idx2>
     [Specifies which images to use as the initial pair.  Very useful指定初始的圖像對
      when the automatically chosen pair results in a bad
      reconstruction.]

  --sift_binary <sift>
     [The location of the SIFT binary on your installation, e.g.,指定SIFT的位置
     '/usr/bin/sift' or '/cygdrive/c/usr/bin/siftWin32.exe'.]

  --add_images <add_list>
     [Given an existing reconstruction specified with the --bundle添加新的圖檔
      option, attempts to add the images listed in the file <add_list>
      to the reconstruction, writing the results to the file
      'bundle.added.out'.  The new list of images is written to
      'list.added.txt'.  Use the 'extract_focal.pl' script to generate
      the file <add_list> from a directory of JPEGs, but note that the
      correct path to these images must be included -- which may
      require editing the add list file.  Do not include the
      '--run_bundle' option when adding new images.  If the SIFT key
      files have not yet been generated for the new images, bundler
      will try to extract features, but this requires that the
      --sift_binary option be set.]

  --options_file <options_file>
     [Read in a list of options from the specified file.]從特定的檔案讀取項目表。

  --help
     [Print out the complete list of command-line options.]列印完整的選項目錄      
Thanks to Manolis Lourakis and Antonis Argyros for their sparse bundle adjustment package, to David Lowe for SIFT , to David M. Mount and Sunil Arya for their approximate nearest neighborslibrary, and to Matthias Wandel for his excellent 'jhead' program.

Special thanks as well to Kathleen Tuite and Sebastian Koch for testing this distribution.




      

References

[1] Noah Snavely, Steven M. Seitz, and Richard Szeliski.  Photo
    Tourism: Exploring Photo Collections in 3D.  SIGGRAPH Conf. Proc.,
    2006.

[2] Noah Snavely, Steven M. Seitz, Richard Szeliski.  Modeling the
    World from Internet Photo Collections. International Journal of
    Computer Vision (to appear), 2007.

[3] M.I.A. Lourakis and A.A. Argyros.  The Design and Implementation
    of a Generic Sparse Bundle Adjustment Software Package Based on
    the Levenberg-Marquardt Algorithm.  Tech.  Rep. 340, Inst. of
    Computer Science-FORTH, Heraklion, Crete, Greece. Available from
    http://www.ics.forth.gr/~lourakis/sba.      

繼續閱讀