# Workflow for forest Canopy Surface Model generation from UAS imagery using MicMac. This dataset is kindly provided by  "l’Unité Gestion des Ressources Forestières et des Milieux Naturels (GRFMN), Université de Liège". Contact: jo.lisein@ulg.ac.be

# OriConvert is used for 5 purposes:
# 1) Conversion of the embedded GPS data into the micmac format 
# 2) Generate the image pairs file
# 3) Change the coordinate system (from WGS84 to a locally tangent system)
# 4) Compute relative speed of the camera (for GPS delay determination)
# 5) Select a sample of the image block (PATC) for camera calibration.

mm3d OriConvert OriTxtInFile GPS_WPK_Grand-Leez.csv Nav-Brut-RTL ChSys=DegreeWGS84@SysCoRTL.xml MTD1=1 NameCple=FileImagesNeighbour.xml CalcV=1 ImC=R0040536.JPG NbImC=25 

# Tie Point Generation with Tapioca:
Tapioca File FileImagesNeighbour.xml -1

# Camera Calibration with Tapas, using a block of 25 images:
Tapas RadialBasic "R0040536.JPG|R0040537.JPG|R0040535.JPG|R0040578.JPG|R0040498.JPG|R0040499.JPG|R0040579.JPG|R0040538.JPG|R0040577.JPG|R0040534.JPG|R0040497.JPG|R0040500.JPG|R0040580.JPG|R0040456.JPG|R0040616.JPG|R0040576.JPG|R0040496.JPG|R0040617.JPG|R0040455.JPG|R0040457.JPG|R0040615.JPG|R0040539.JPG|R0040501.JPG|R0040581.JPG|R0040533.JPG" Out=Sample4Calib-Rel 

# Visualization of the sub-block orientation with AperiCloud (and meshlab):
AperiCloud "R0040536.JPG|R0040537.JPG|R0040535.JPG|R0040578.JPG|R0040498.JPG|R0040499.JPG|R0040579.JPG|R0040538.JPG|R0040577.JPG|R0040534.JPG|R0040497.JPG|R0040500.JPG|R0040580.JPG|R0040456.JPG|R0040616.JPG|R0040576.JPG|R0040496.JPG|R0040617.JPG|R0040455.JPG|R0040457.JPG|R0040615.JPG|R0040539.JPG|R0040501.JPG|R0040581.JPG|R0040533.JPG" Sample4Calib-Rel Out=Sample4Calib-Rel.ply 

# Optionnaly, if meshlab is installed:
meshlab Sample4Calib-Rel.ply

# Orientation of the complete block in a relative system
Tapas RadialBasic "R.*.JPG" Out=All-Rel Incal=Sample4Calib-Rel 

# Determination of the GPS delay (improvement of the georeferencing) with CenterBascule
CenterBascule "R.*.JPG" All-Rel Nav-Brut-RTL tmp CalcV=1

# OriConvert is (again) used for taking the delay into account:
mm3d OriConvert OriTxtInFile GPS_WPK_Grand-Leez.csv Nav-adjusted-RTL ChSys=DegreeWGS84@SysCoRTL.xm MTD1=1 Delay=-0.0854304

# Georefenrencing the aerotriangulated model with CenterBascule
CenterBascule "R.*.JPG" All-Rel Nav-adjusted-RTL All-RTL

# Change the coordinate system with ChgSysCo:
mm3d ChgSysCo  "R.*JPG" All-RTL   SysCoRTL.xml@SysCoBL72_EPSG31370.xml   All-BL72

# creation of the camera position (cloud):
AperiCloud "R.*.JPG" All-BL72 Out=All-BL72-cam.ply WithPoints=0

# Optionnaly, if meshlab is installed:
meshlab All-BL72-cam.ply

# Dense-matching with Malt. Here, we aren't interested in the generation of orthophoto.
Malt Ortho "R.*JPG" All-BL72 DirMEC=MEC DefCor=0 AffineLast=1 Regul=0.005 HrOr=0 LrOr=0 ZoomF=1

# Convert the Digital surface model in 8bits:
to8Bits MEC/Z_Num8_DeZoom1_STD-MALT.tif

# export the dense point cloud and color it with Nuage2Ply:
Nuage2Ply "MEC/NuageImProf_STD-MALT_Etape_8.xml" Scale=8 Attr="MEC/Z_Num8_DeZoom1_STD-MALT_8Bits.tif" Out=CanopySurfaceModel.ply

# Optionnaly, if meshlab is installed:
meshlab CanopySurfaceModel.ply


# Enjoy!























