Multi-view 3D Reconstruction

Colored 3D models and augmented reality from a single turntable video

Put an object on a turntable, record one video while it spins, and get back a colored 3D model of it. This project does that with a classical computer vision pipeline, written in Python with only NumPy and OpenCV: no depth sensor, no deep learning, and no manual annotation.

The object sits on a yellow cup in the middle of the turntable, in front of a blue background. Around it, a printed circular marker spins with it. The marker tells the program where the camera is in every frame, and the outline of the object seen from all those viewpoints is enough to carve its shape out of a block of voxels.

The four reconstructed objects. Drag to orbit, ctrl + scroll or pinch to zoom, or open the full viewer.

How it works

  1. Camera calibration. A video of a chessboard gives the camera’s focal length, optical center and lens distortion. The board is found automatically in 150 frames, 30 well-spread views are used for the calibration, and views with corners misplaced by motion blur are detected and discarded. The final re-projection error is 0.6 pixels.
  2. Marker detection and tracking. The marker has 24 marks, and each one encodes its number with 5 dots. Every 5 frames the marks are detected from scratch: the frame is thresholded, the contours are simplified to polygons, and the ones with the right shape are kept and their dots are read. In between, they are tracked with optical flow, and the inner corner of each mark is refined to sub-pixel accuracy.
  3. Camera pose. Knowing where each mark is on the marker and where it appears in the image, the camera’s position and orientation are computed for every frame. There are two implementations: OpenCV’s solvePnP and a factorization of the homography between the marker plane and the image. Misread marks are found by their re-projection error and dropped, and the remaining ones are re-projected with a mean error of about 0.6 pixels.
  4. Silhouettes. Each frame is split into object and background. The background is found by its blue hue, and the result seeds a watershed segmentation that cleans up the boundary. Against hand-made ground truth masks, it reaches 99.2% precision and 97.2% recall in the region around the object.
  5. Space carving. The volume above the cup is filled with a grid of 128 × 128 × 77 voxels, 1.17 mm each. In every frame, each voxel is projected into the image with the camera pose, and if it falls on the background it is removed. What survives all the frames is the visual hull of the object.
  6. Voxel coloring. Each surface voxel takes the average color of the pixels it projects onto, using only the frames where it is visible (found with a z-buffer) and favoring the ones that see it head-on.

The same camera poses also drive an augmented reality mode, which draws virtual objects into the video: a cube around the object, hidden where it passes behind it, a copy of the marker floating above it, the axes of the marker, and the marks re-projected onto the turntable.

Space carving (left): the silhouette, the carved volume and the number of voxels left. Augmented reality (right): virtual objects anchored to the marker. Both at 2× speed.

Results

Four objects on the turntable: a toucan plush, a toy triceratops, a pack of crackers and a small statuette. Below each one, its reconstructed model rendered from the same viewpoint, with matching shape and colors.

Video frames (top) and the reconstructed models rendered from the same camera pose (bottom).

Every frame of the four videos was used: none was rejected for a poor camera pose. A reconstruction takes 50 to 100 seconds on a 4-core laptop, most of it spent on the silhouettes, which are computed in parallel.

ObjectFramesRe-projection error (mean / max)VoxelsTime
Toucan plush8420.61 / 1.29 px87,974100 s
Triceratops6450.59 / 1.29 px35,23852 s
Cracker pack4910.60 / 1.24 px97,60257 s
Statuette6070.59 / 1.21 px26,61849 s

The models are saved as PLY files, which open in MeshLab, Blender or CloudCompare, and the program can also write the self-contained WebGL viewer shown above.

Limitations

Silhouettes can only remove what is visible against the background, so concave regions that never appear on the outline of the object, such as the inside of a bowl, stay filled. The cup is part of the silhouette too, and leaves a thin yellow base under every model.

The model is also only as good as the silhouettes. The gap between the triceratops’ legs is not carved because the segmentation marks it as part of the object. Tuning the segmentation fixes it, but it is left as is to show how segmentation errors carry over to the model.

Code

The code is on GitHub, as a Python package with a command line tool for each step, from calibration to the 3D viewer, along with the videos and the ground truth masks. The viewer above is rebuilt by GitHub Actions directly from the raw videos whenever the code changes.