Introduction: Free Photogrammetry on Mac OS: From Photos to 3D Models

Photogrammetry is the use of images/photography to measure distances between objects (thanks Webster). But for modern purposes, it is often used to make a 3D model of somethings from the real world without needing a 3D Scanner.

There is plenty of software out there that you can use for photogrammetry, including some great free options, but I noticed that many (such as Meshroom) didn't have Mac builds available. Or they would require a graphics card with CUDA support (not typical with things like a Macbook). So that meant some digging around.

I finally stumbled on this excellent article: https://peterfalkingham.com/2017/12/17/free-photog...

This lead to a follow-up build script: https://peterfalkingham.com/2018/04/01/colmap-open...

It took me a while to get it working, but once I got it going, I was pretty pleased with the results I started getting. So, I'm going to break down the steps a little more, especially for you Mac users out there.

Step 1: Get COLMAP

COLMAP (https://colmap.github.io/install.html) is a nice, little free tool for getting started with photogrammetry. I tried it on its own at first, but some of the later steps required CUDA. So I had to start looking again. That is why we will use other software for the later steps.

Downloading COLMAP is easy. You can follow the instructions here: https://colmap.github.io/install.html

Or you can look at the latest release on their github page: https://github.com/colmap/colmap/releases and download the latest COLMAP-{version}-mac-no-cuda.zip

Once you dowload the zip, unzip it and stick the COLMAP app into your Applications folder. After, right click COLMAP.app and select "Open" and trust the app. You might have to do it twice, because sometimes the first time it crashes.

You can test running it running this command:

/Applications/COLMAP.app/Contents/MacOS/colmap -h

You might get an error like this:

Library not loaded: @rpath/libamd.2.dylib

If that occurs, run this:

brew install suite-sparse
for lib in /Applications/COLMAP.app/Contents/Frameworks/*.dylib; do
for dep in $(otool -L "${lib}" | grep @rpath | awk '{print $1}'); do
install_name_tool -change "${dep}" "@executable_path/../Frameworks/$(basename "${dep}")" "${lib}"
done
done

Step 2: Get and Build OpenMVS

The next program that I use to help finish building the 3d models is OpenMVS (https://github.com/cdcseacave/openMVS/). You are going to have to build this on your machine, so I will attempt to make this as painless as possible.

The link to the instructions for getting and building OpenMVS on a Mac is here: https://github.com/cdcseacave/openMVS/wiki/Buildin...

but I did have to modify slightly. Here is what I did:

#Install dependencies
brew update
main_path=`pwd`
brew install boost
sed -i.bak -r 's/NO_ZSTD=1/NO_ZSTD=0/' /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/boost.rb
brew reinstall boost --build-from-source
brew install eigen opencv cgal ceres-solver

#VCGLib (Required)
git clone https://github.com/cnr-isti-vclab/vcglib.git vcglib

#Getting the OpenMVS sources:
git clone --recurse-submodules https://github.com/cdcseacave/openMVS.git

#Build OpenMVS
mkdir openMVS_build && cd openMVS_build
cmake . ../openMVS -DCMAKE_BUILD_TYPE=Release -DVCG_ROOT="$main_path/vcglib" -DOpenMVS_USE_CUDA=OFF -DOpenMVS_USE_OPENMP=OFF -G "Xcode"
xcodebuild -configuration Release

Step 3: Create a Photogrammetry Script

I then created a script based on the one from here: https://peterfalkingham.com/2022/02/05/photogrammetry-testing-colmap-3-7-and-openmvs-v2-0-now-with-cuda/. Here is what I ended up with (pay attention to the notes in the script, since it requires you to set some locations):

Photogrammetry.sh

# These parameters are specific to computer

# Store current Directory:
currDir=$PWD
# get folder name as variable
myfolder=${PWD##*/}
# Set colmap directory (change this to where you've downloaded colmap, replace 'dev' with version number if necessary):
colDir=/Applications/COLMAP.app/Contents/MacOS/colmap
# Set openMVS directory (change this to the 'bin/Release' folder where you've downloaded and built openMVS)
oMVS=/Users/joecooning/Projects/openMVS_build/bin/Release
# Set Working Directory (I create a temporary workspace folder in my 'Projects' directory to process data in)
workDir=/Users/joecooning/Projects/3dscans/workspace/$myfolder/
mkdir $workDir
cp *.jpg $workDir/
cp *.JPG $workDir/
cd $workDir


$colDir feature_extractor --database_path database.db --image_path .
$colDir exhaustive_matcher --database_path database.db

mkdir sparse

$colDir mapper --database_path $workDir/database.db --image_path . --output_path $workDir/sparse
$colDir image_undistorter --image_path . --input_path ./sparse/0/ --output_path myundist

cd myundist

$oMVS/InterfaceCOLMAP -i $workDir/myundist -o proj.mvs
$oMVS/DensifyPointCloud proj.mvs
$oMVS/ReconstructMesh proj_dense.mvs
$oMVS/RefineMesh --resolution-level 1 proj_dense_mesh.mvs
$oMVS/TextureMesh --export-type obj -o $myfolder.obj proj_dense_mesh_refine.mvs

mkdir $currDir/model/
cp *.obj $currDir/model/
cp *.mtl $currDir/model/
cp *Kd.jpg $currDir/model/
cd $currDir

Step 4: Run the Script

Now that you have the script, you can take photos of an object that you want to make a 3d model of. There are other articles and videos out there that can give you some great advice on how to best take photos for the purpose of photogrammetry (such as this one: https://www.tested.com/art/makers/460142-art-photo...).

But those photos into a folder, the copy the script you made into the folder.

From you terminal, go to the folder where the photos and script are and run:

sh Photogrammetry.sh

The script will then do the rest of the work for you. Please note that this can take quite a bit of time to process (especially if you are using a lot of high-res photos). I would suggest trying some smaller photo sets first. Some simple, sample photo sets can be found here: (http://www.regard3d.org/index.php/demo-models)

Step 5: Check Out You Model

Once the script finishes running, you should have an OBJ file exported into a model file where you had the photos. If you go to your workspace folder, you can find intermediate PLY models that you can check out in programs such as MeshLab.

Hope you enjoy and let me know if it worked for you. I'm also open to suggestions for improvements in the process.

1 Hour Challenge

Participated in the
1 Hour Challenge