## 3D 點雲建模 (在server上) ### 資料蒐集 詳細3D點雲建模方法細節可以詢問定位組建模的人 先在實驗場地錄製一段影片(建議用無人機,如果不是用無人機需調整內參),盡量之後無人機或可能會飛到的地方都要拍攝到,並需要額外拍攝四張基準照片。 將錄製好的影片以固定間個取出約500張frames:  四張基準照片則分別是一張original(及面向目標拍攝一張照片),up(original向上一公尺),right(original向右一公尺),forward(original向前一公尺)。  ### 建模環境 :::info ``` ssh drapeegoo@140.113.195.240 -p 55688 ``` Under ` ~/Documents/VBGPS/Hierarchical-Localization/` ``` conda env create -f environment_Hloc.yml python=3.7.11 // drapeegoo server上已經建好conda環境了 可以不用跑這行 conda activate Hloc ``` ::: ### [Colmap](https://colmap.github.io/gui.html) installation (drapeegoo已經裝好了) :::info ``` sudo apt-get install \ git \ cmake \ ninja-build \ build-essential \ libboost-program-options-dev \ libboost-filesystem-dev \ libboost-graph-dev \ libboost-system-dev \ libboost-test-dev \ libeigen3-dev \ libflann-dev \ libfreeimage-dev \ libmetis-dev \ libgoogle-glog-dev \ libgflags-dev \ libsqlite3-dev \ libglew-dev \ qtbase5-dev \ libqt5opengl5-dev \ libcgal-dev \ libceres-dev ``` ``` git clone https://github.com/colmap/colmap.git cd colmap git checkout dev mkdir build cd build cmake .. -GNinja -DCMAKE_CUDA_ARCHITECTURES=sm_70 ninja sudo ninja install ``` ``` sudo apt-get install -y \ nvidia-cuda-toolkit \ nvidia-cuda-toolkit-gcc ``` ::: ### 資料夾準備 :::info Under ` ~/Documents/VBGPS/Hierarchical-Localization/` ::: - 首先建立一個資料夾於`datasets/`目錄下 - 建立三個子資料夾於上一步的資料夾中,分別為: `db_images/` `images_upright/` `queries/` - 將所有要建立模型所蒐集之圖片(**之前從錄製影片取出的約500張圖片以及四張基準圖片都要**)至 `db_images/` - 複製一個 **intrinsic.txt** (可從 `/1206_drone/queries/intrinsic.txt` 複製) 到 `queries/` ``` $ mkdir [datasets_name] $ cd [datasets_name] $ mkdir db_images/ images_upright/ queries/ $ cp ../1206_drone/queries/intrinsic.txt queries/ ``` - 更改 intrinsic.txt 文件( **width**, **height** to 改為對應 `./db_images`中照片的長寬值) ``` SIMPLE_RADIAL [images width] [images height] 512.015 480 360 -0.00169481 ``` ### SfM (Start to build) :::info Under ` ~/Documents/VBGPS/Hierarchical-Localization/` Environmemt: conda activate Hloc ::: 利用以下指令Construct 3個bin檔於 `outputs/[datasets_name]/sfm_superpoint+NN` ``` python3 -m hloc.pipelines.VBgps.Sfm --name [datasets_name] ``` ### Extract global feature :::info Location ` ~/Documents/VBGPS/Hierarchical-Localization/` Environmemt: conda activate Hloc ::: Extract global feature from database ``` python3 -m hloc.pipelines.VBgps.extract_db_global --name [datasets_name] ``` 下載以下兩個資料夾: `/Hierarchical-Localization/outputs/[datasets_name]/sfm_superpoint+NN/` `/Hierarchical-Localization/datasets/[datasets_name]/db_images/` --- ## 更改model的格式 ### 將bin格式更改為.nvm格式並編輯Coordinate_demo.txt 電腦需先安裝COLMAP GUI, VisualSfM :::info Install [COLMAP](https://colmap.github.io/gui.html), [VisualSfM](http://ccwu.me/vsfm/index.html) ::: 將server端建模所得到的 3 個 bin檔成nvm,使用COLMAP程式 1. 打開 **COLMAP** GUI 並 import model  2. 選擇 `/sfm_superpoint+NN/`資料夾位置  3. Open database  4. 選擇`/sfm_superpoint+NN/`中的database.db  5. Select Images  6. 選擇`/db_images/`資料夾  7. 找出四個fundamental images分別**點擊**他們  8. 可以看到每個照片的 **qw qx qy qz tx ty tz**  9. 開啟server drapeegoo中的`~/Documents/VBGPS/VBGPS_coor_transform/Coordinate_demo.txt`並分別將它們(**qw qx qy qz tx ty tz**)記錄下來 (four images pose)  10. 選擇 **Export model as**  11. 選擇 **.nvm** 格式並儲存  ### Convert nvm to ply 1. 開啟 VisualSFM GUI, load 剛剛轉換完 **.nvm** 模型檔案  2. SfM -> Extra Functions -> Save Current Model  3. 儲存模型為 **[model_name].ply**  4. 開啟儲存完的 **.ply** 檔並查找如果出現 **(-1.#IND)** 的列直接將那列刪除  5. 將 **(-1.#IND)** 全部刪除後,把此ply檔複製到大筆電的`~/Desktop/ray/VBGPS_client_outdoor_demo/Examples/Monocular/model/` ### Convert ply to txt :::info 到大筆電的路徑 Under `~/Desktop/ray/VBGPS_client_outdoor_demo/Examples/Monocular/model/` ::: 再將.ply的模型格式轉為.txt格式 先確認 **.ply** 檔案已於 `~/Desktop/ray/VBGPS_client_outdoor_demo/Examples/Monocular/model/` 執行model.out將ply檔轉成model.txt檔,再更名為model_name.txt ``` ./model.out [model_name].ply mv model.txt [model_name].txt ``` --- ## 座標系統轉換 ### Environment :::info 回到server(drapeegoo) Under ` ~/Documents/VBGPS/VBGPS_coor_transform/` ``` conda activate Hloc ``` ::: ### Transform 可以自行更改 **Coordinate_Transform.py** 中的 ***old_coor*** 矩陣 (更改方式取決於4張fundamental images的相對距離所的,單位為公尺,第一列為X代表original與right的距離,第二列為Y(original與up的距離),第三列為Z(original與forward的距離)  如果蒐集四張基準照片時,都是距離1公尺則須改回: 1 0 0 0 1 0 0 0 1 Transform: ``` python3 Coordinate_Transform.py ``` 可以得到一個 **init.xml**, 將它移動到大筆電的`~/Desktop/ray/VBGPS_client_outdoor_demo/Examples/Monocular/config/`路徑 --- ## Dense-Flow estimation (Stage 2 模型的模型訓練,如果沒有要訓練新的模型可跳過) :::info 回到server端的NeuralMarker資料夾 ``` ssh drapeegoo@140.113.195.240 -p 55688 ``` Under ` ~/Documents/NeuralMarker/neuralmarker_original/NeuralMarker/` ``` conda activate neuralmarker ``` ::: ### Train Preparing 訓練時,我們會使用[Weights & Biases](https://wandb.ai/site)來監控訓練過程,先到官網創建帳號並登入。  接著點選左邊的**Create new project**  建立完後務必記得**Project name** 以及 **Entity**  接著開啟`/NeuralMarker/train.py`,並將project與entity更改為weight & Biases中的**Project name** 以及 **Entity**   若要查看已整理完的訓練資料集可於`/NeuralMarker/data/`查看,若要更改訓練參數可於`/NeuralMarker/configs/params_default.yml`中修改 ### Training :::info Under `/NeuralMarker/` ::: 接著執行train.py開始訓練,在下面輸入實驗名稱。 ``` python train.py ```  輸入完後即會開始訓練,接著可以到Weight & Biases可以看到對應的實驗命稱,並即時監控所有訓練過程數據   ### Training Results 訓練完的結果可在`/NeuralMarker/snapshot` 資料夾名稱為開始訓練的時間,其中會包含此次訓練的參數以及訓練的中間結果以及最終結果。  ### Evaluation 若要測試訓練完的weight,可用以下指令 ``` python Estimate_simple.py --current_image_root [無人機畫面截圖] --target_image_root [Target圖片路徑] --save_root [結果儲存路徑] --encoder [使用的image encoder(Twins/cnn))] --model [weight的路徑] Example: python Estimate_simple.py --current_image_root ./0711_indoor_results/Stage1_res.jpg --target_image_root ./0705_indoor_results/Frame720.jpg --save_root ./upload_test1/ --encoder twins --model ./snapshot/twins_without_pretrained_kp_loss_6eps/checkpoint_latest.pth ``` 執行完成應該如以下所示:  儲存路徑會包含多個結果圖:  可特別觀察**points_matchings_direct**即為到時候飛行是預估出的對齊圖,以及飛行方向 --- ## Demo :::info 大筆電目前的的測試環境 Cuda == 8.0 OpenCV == 3.X ::: ### Compiling 大筆電client端的編譯 :::info 每次更動client端的程式及需要編譯 Under `~/Desktop/ray/VBGPS_client_outdoor_demo/` ::: ``` ./build.sh ``` 確認編譯成功沒有任何error ### 建一個新的程式 假如要在大筆電複製一個新的client程式 :::info 先到client的程式位置 Under `~/Desktop/ray/VBGPS_client_outdoor_demo/Examples/Monocular/` ::: 假如複製一個程式檔new_test.cc 需到`~/Desktop/ray/VBGPS_client_outdoor_demo/CMakeLists.txt`加入你所新增的程式檔名  再重新編譯確定無錯誤 ``` ./build.sh ``` ### 建一個 config file (test.xml) :::info Under `~/Desktop/ray/VBGPS_client_outdoor_demo/Examples/Monocular/config/` ::: 需要再建一個config檔案,可先從 `config_1206_drone_rm_IND.xml` 複製一個 `test.xml` ``` cp config_1206_drone_rm_IND.xml test.xml ``` 接著編輯 `test.xml` ,更改其中的 `<MODEL_NAME>` 成你的txt模型路徑  ### Run server (on server) :::info ``` ssh drapeegoo@140.113.195.240 -p 55688 ``` Under `~/Documents/VBGPS/Hierarchical-Localization/` ``` conda activate Hloc ``` ::: 執行Server端的程式,依照復拍地點選擇相應的datasets資料夾,output資料夾,還有復拍的Target圖片路徑 ``` python3 -m hloc.pipelines.VBgps.pipline_stage1_and_2.py --dataset datasets/[datasets_name] --outputs outputs/[datasets_name] --target [Target_image_path] ``` 以電資大樓室內demo場地為例: ``` python3 -m hloc.pipelines.VBgps.pipline_stage1_and_2.py --dataset datasets/1206_drone --outputs outputs/1206_drone --target Frame720.jpg ``` 如果想要更改Server端,Stage 2所使用的weight,開啟`/Hierarchical-Localization/hloc/pipelines/VBgps/pipline_stage1_and_2.py`,並更改147行中,--model後面**default之路徑**  得到以下畫面後,client端才可以開始執行復拍任務  ### Get Target image pose(取得Target image pose) :::info 大筆電上 Under `~/Desktop/ray/VBGPS_client_outdoor_demo/Examples/Monocular/` ::: ``` ./client_get_target_new ../../Vocabulary/ORBvoc.txt [Target_image_path] config/test.xml ``` 以電資大樓室內demo場地為例: ``` ./client_get_target_new ../../Vocabulary/ORBvoc.txt Frame720.jpg config/config_1206_drone_rm_IND.xml ``` 執行以下client端之前需確認 `target.xml` 已經在 `/VBGPS_client/Examples/Monocular/config/`路徑下 ### Run client :::info 若要在沒有網路的地方demo,需要帶網卡(老伯位子上),大筆電wifi接連無人機的基地台,網卡wifi接手機網路。在執行: ``` cd Desktop/ymc/ ./setNetwork.sh ``` ::: :::info Under `~/Desktop/ray/VBGPS_client_outdoor_demo/Examples/Monocular/` ::: client執行測試影片的指令如下 (Replace `test.xml` by you model config) ``` ./client_video_new ../../Vocabulary/ORBvoc.txt video [test_video_path] config/test.xml config/init.xml config/target.xml ``` Example: ``` ./client_video_new ../../Vocabulary/ORBvoc.txt video ../../video/ES_ray/test3.avi config/config_1206_drone_rm_IND.xml config/1206_id_init.xml config/target.xml ``` 執行無人機復拍任務指令 ``` ./client_Ray_drone_stage123_indoor ../../Vocabulary/ORBvoc.txt config/test.xml config/init.xml config/target.xml ``` Example: ``` ./client_Ray_drone_stage123_indoor ../../Vocabulary/ORBvoc.txt config/config_1206_drone_rm_IND.xml config/1206_id_init.xml config/1206_id_new_target.xml ``` 將大筆電command line出現Finish!!!即表示完成復拍  會有兩個或三個結果圖(Stage2_res可能沒有) Server端的會存第二階段微調的所有過程圖片於: `~/Documents/VBGPS/Hierarchical-Localization/datasets/[datasets]/stage_2_res/`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up