Depth Between Two Puzzle Views
The loop in my disentanglement puzzle looks innocent in either photograph. In the stereo flipbook, it suddenly hangs in front of the wire frame. That impression comes from a small disagreement: the loop appears at a slightly different horizontal position in each eye’s view.
Computer vision calls that difference disparity. With a calibrated stereo pair, disparity can also estimate distance. The following examples use a camera separation of 60 mm and a focal length of 800 pixels. They treat the left and right images as already aligned, so corresponding points sit on the same image row.
let baseline = 60.0 // millimetres
let focalLength = 800.0 // pixels
let points = [(120.0, 108.0), (160.0, 136.0)]
for (left, right) in points {
let disparity = left - right
if disparity > 0 {
let depth = focalLength * baseline / disparity
print("disparity: \(disparity) px, depth: \(depth) mm")
}
}
The Perl version makes the same calculation for the same two points:
use strict;
use warnings;
my $baseline = 60; # millimetres
my $focal_length = 800; # pixels
my @points = ([120, 108], [160, 136]);
for my $point (@points) {
my ($left, $right) = @$point;
my $disparity = $left - $right;
next unless $disparity > 0;
my $depth = $focal_length * $baseline / $disparity;
print "disparity: $disparity px, depth: $depth mm\n";
}
Both report depths of 4,000 mm and 2,000 mm: the point with twice the disparity is half as far away. Similar triangles give us that inverse relationship. The programs skip zero and negative disparities because this simple camera arrangement cannot turn them into a positive finite depth.
The arithmetic is the easy part. Matching the same glint of metal across two photographs can be tricky, especially when one loop hides another. Small measurement errors matter more at long distances, where disparity approaches zero. For a flipbook, careful registration and consistent camera placement make the depth estimate—and the illusion—more dependable.