System designApplication note

Measuring pole lean angle from a segmentation mask with PCA

Compute a pole's in-plane lean from its segmentation mask with PCA: the angle formula, an error budget, frame gates and the single-camera floor to plan around.

LumaSpec Vision12 min read Share on LinkedIn

On this page 10 sections
  1. 01How do you measure pole lean from a segmentation mask?
  2. 02How accurate is a single-camera lean reading?
  3. 03Why is the reading a floor, and when can you trust it?
  4. 04How much does camera roll move the angle?
  5. 05Which frames do you keep for each pole?
  6. 06How many pixels does the camera need on the trunk?
  7. 07Which camera runs the segmentation on the vehicle?
  8. 08When does PCA on the whole trunk give a wrong angle?
  9. 09What should you check before you order the hardware?
  10. 10Questions

Segment a utility pole's trunk, run PCA on the mask pixels, and the angle of the principal axis against the image vertical is the in-plane lean — no calibration and no extra hardware beyond the camera you already carry. For inspection crews and utilities piloting drive-by pole surveys, this guide gives the closed-form angle formula, an error budget you can defend, the frame gates that keep mask noise out of the statistics, and the one physical limit a single camera cannot remove: every reading is a floor on the true lean, so a flag is safe on one pass and a clearance is not. In one 556-pole neighborhood run, 547 poles read under 10°, 9 landed in the 10-15° review band, and none crossed 15°. The same math runs on a phone, a smart camera or a GigE camera feeding a vehicle PC.

How do you measure pole lean from a segmentation mask?

Compute the covariance of the mask's pixel coordinates and take half the atan2 of the cross term: θ = ½·atan2(2σxy, σyy − σxx), measured from the image vertical, which is the closed-form PCA principal axis and a total-least-squares line fit in one pass.

The recipe:

  1. Segment the trunk only — no crossarms, guys, wires or background. Everything below assumes one straight-ish shaft in the mask.
  2. Take the mask's pixel coordinates (x, y) in image convention: x right, y down.
  3. Compute the three second moments over the N mask pixels.
  4. The absolute value of θ is the lean from vertical; its sign is the tip direction within the frame.
σxx = Σ(xi − x̄)² / N σyy = Σ(yi − ȳ)² / N σxy = Σ(xi − x̄)(yi − ȳ) / N θ = ½ · atan2(2σxy, σyy − σxx)

PCA's major eigenvector is the axis, and the half-angle identity collapses the eigendecomposition into that single atan2. Every mask pixel votes rather than just the two endpoints, which resists edge fraying. The whole fit is a few lines with any matrix library: two means, three moments, one atan2.

The formula degenerates when the mask is wider than it is tall: σyy − σxx goes negative and the fit reports a near-horizontal axis. That failure is what the elongation gate in the frame-selection section catches before it can reach your statistics.

No trained segmenter yet? A threshold-then-morphology workflow for part detection produces a usable trunk mask from a high-contrast frame.

How accurate is a single-camera lean reading?

Plan on ±0.5° frame-to-frame repeatability and about ±2° absolute accuracy from a level camera on a straight road: pixel quantization contributes 0.03°, mask-edge noise a few tenths, and camera roll most of the rest.

The sensor is never the limit; the mask and the mount are.

Error source Size Countermeasure
Pixel quantization 0.03° none needed
Mask-edge noise ±0.3-0.5° frame gates below
Mount roll, constant 0.5° measure once, subtract
Driving roll up to ±2° drop turn frames
Perspective floor any under-read two passes at 90°

Every term except roll and perspective scales as 1/h: halve the trunk's pixel height and you double the error.

Why is the reading a floor, and when can you trust it?

One camera sees only the lean component across the frame — tan θimg = tan θtrue × cos α — so a pole truly at 15° reads 10.7° when its lean direction runs 45° to the camera, and one that tips straight toward the vehicle reads 0°.

The out-of-plane lean component projects onto the image scaled by cos α, where α is the angle between the lean direction and the image plane; the vertical component is unchanged. The reading can therefore never exceed the truth.

Lean direction vs image plane (α) Reading of a true 15° lean
0° (broadside) 15.0°
30° 13.1°
45° 10.7°
60° 7.6°
90° (driving straight at it) 0°

Two passes fix the decision. Drive the street and the cross street about 90° apart and keep the larger reading. The larger of the two projections is bounded below by arctan(tan θtrue × cos 45°), which for a true 15° pole means at least 10.7° — so with two perpendicular passes, 10.7° becomes the effective review floor for a 15° threshold.

If you later mount cameras at fixed oblique angles and want true three-dimensional angles, you are building an image-to-ground transform — the same math as vision pick coordinates on a tilted plane.

How much does camera roll move the angle?

The vertical reference is the frame edge itself, so a degree of camera roll is a degree of angle error: a 0.5° mount offset shifts every pole by 0.5°, and body roll of a few degrees on a flat road does the same to borderline readings.

Three tiers, three treatments. A constant mount offset is a bias: measure it once with a phone level app and subtract it from every reading. Slow body roll on straight, flat roads stays within a few degrees and only matters to readings near the threshold. Turns couple roll and heading change, and correcting them is wasted effort — drop those frames instead.

Commit to this: reject any frame whose GPS heading changes faster than about 5°/s, which on a residential route discards little except intersections. With ±2° of residual roll and a 15° threshold, only readings above about 13° can be false flags, because the pole must sit within 2° of the threshold for roll to push it over — gate the 13-15° band to straight-road frames and send it to review.

Keep every vehicle's camera in one orientation. A unit mounted upside down produces mirrored, sign-flipped angles; fix the orientation once in software, as in camera mounted upside down: flip the image 180 degrees in software, so all units share one vertical.

Which frames do you keep for each pole?

Gate every frame and lock the pole's angle from the median of the best five: keep frames with axis elongation λ1/λ2 ≥ 20, a trunk mask at least 300 px tall, the pole top at least 10% of frame height below the frame edge, and detector confidence ≥ 0.6.

Why each gate earns its place:

  • Elongation λ1/λ2 ≥ 20. The eigenvalue ratio of the covariance equals (length ÷ width)² for a filled shape, so a clean 1846 × 123 px trunk scores about 225 and a merged blob scores under 10. Below the gate, the mask is usually trunk plus crossarm or background, and the atan2 goes unstable. This is the same anisotropy idea as measuring image pattern strength with spatial regularity: a mask with no dominant direction has no trustworthy angle.
  • Trunk height ≥ 300 px. Quantization at 300 px is 0.970 ÷ 300 rad = 0.185° per pixel, so single-frame scatter stays under about 0.5°; shorter trunks scatter wider than the review band.
  • Pole top ≥ 10% of frame height below the top edge. Truncation does not bias the angle of a straight trunk, but masks that touch the frame edge drag in crossarms and secondary wires and then fail the elongation gate; the margin keeps the mask trunk-only.
  • Detector confidence ≥ 0.6. Below that, boundaries fray, and a frayed side biases σxy toward the fray.

Then lock: rank the surviving frames and take the median angle of the top five. The median kills single-frame glitches, and if those five spread more than 1.5° apart, record the pole for review instead of recording a number. Four gates, one median, one spread check — that is the whole frame selection.

How many pixels does the camera need on the trunk?

Size for at least 100 pixels across a 400 mm trunk and about 1000 pixels of visible trunk height, which is 4 mm/px or better at a 10 m standoff — about 3300 sensor pixels across a 13 m field of view.

The two counts do different jobs. Trunk height drives angle precision, since every error term scales as 1/h; trunk width keeps the covariance two-dimensional, because a sliver a few pixels wide frays and biases σxy. The arithmetic from the worked example: 100 px on a 400 mm trunk means 4 mm/px, and 4 mm/px across a 13 m field means 13 000 ÷ 4 = 3250 sensor pixels. The phone's 4000 pixels deliver 3.25 mm/px and 123 px on the trunk with margin to spare.

Feed your own standoff, field width and trunk width into the camera resolution calculator:

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

Which camera runs the segmentation on the vehicle?

Two builds work: a smart camera that runs detection, tracking and the angle math on the device, or a global-shutter area scan camera feeding a vehicle PC — the smart camera wins on wiring and simplicity, the PC build when you also log GPS and render the marked-up video.

For the on-device build, the MV-SC6050C-08M-XBN pairs a 5 MP color sensor with a global shutter and an 8 mm lens on an M12 mount.

Smart cameras & vision sensorsHikrobot MV-SC6050C-08M-XBN SC6000 Series Smart Camera, 5 MP, Color, 8 mm focal length, M12-mount, Multi-color light sourceMV-SC6050C-08M-XBN
Interface
GigE
Resolution
5 MP
Sensor format
1/1.45"
Shutter
Global
$3,449.00 · quotedView and quote

That 8 mm lens over a 1/1.45-inch, 4:3-format sensor covers about 11 m of width at a 10 m standoff (half-angle atan(4.4 ÷ 8) ≈ 28.9°, width = 2 × 10 m × tan 28.9° ≈ 11.0 m), about 4.3 mm/px at the 2592-pixel width of a 5 MP 4:3 sensor. A 400 mm trunk then spans about 94 pixels — just under the 100-pixel target — so close the standoff to 9 m: width 2 × 9 m × tan 28.9° ≈ 9.9 m, 3.8 mm/px, 104 px on the trunk.

For the PC build, the MV-CU020-90GC is a 2.5 MP color camera with a global shutter on GigE, and its C-mount takes whatever focal length the standoff needs.

Area scan camerasHikrobot MV-CU020-90GC 2.5 MP Area Scan Camera, GigE, GMAX4002, ColorMV-CU020-90GC
Sensor format
1/1.7"
Lens mount
C-mount
Interface
GigE
Resolution
Up to 3 MP
$309.00View partBuild a system with it

Pick that focal length with the lens focal length calculator: standoff and wanted field width in, focal length out. On a moving vehicle, global shutter is not optional — a rolling sensor reads rows in sequence, so vibration during readout skews verticals, which is precisely the quantity being measured. Both builds start at the camera finder.

When does PCA on the whole trunk give a wrong angle?

PCA returns one average axis, so a pole that is straight at the base but bent near the crown can read nearly vertical: split the mask at two-thirds height, fit the piece above the split separately, and flag the pole when the two angles differ by more than 3°.

A lean is a rigid tilt and a bend is a curve, and utilities treat them as different defects; the whole-mask average merges them into one misleading number. The two-piece fit costs one extra pass over the pixels and separates the cases.

Taper is not a problem — a cone has a well-defined axis and the covariance handles it. Two things are. A crossarm or wire merged into the mask pulls σxy toward the merged object, which the trunk-only rule and the elongation gate both guard against. And a mask split in two by a wire crossing the trunk needs repair before the fit: take the largest connected component, or merge components whose centroids fall on one line.

More mask-based measurement techniques are collected on the systems topic page.

What should you check before you order the hardware?

Four checks from your own route decide the order: the threshold you report against, the standoff your streets allow, the pixels your optics put on a 400 mm trunk at that standoff, and whether the route turns inside a pole's visibility window.

  • Write the policy first. Threshold and action per band — flag at the threshold, review below it. Utilities set their own limits, and one run's numbers are only comparable within one policy.
  • Measure the standoff your streets allow. A parking lane puts the camera 3-4 m from the poles, a driving lane 5-6 m; only wide collector roads give 10 m.
  • Compute pixels on the trunk. mm/px = field width ÷ sensor pixels, then 400 mm ÷ mm/px; keep the result at 100 or better, or shrink the standoff.
  • Global shutter on anything vehicle-mounted, for the rolling-shutter skew reason above.
  • Plan two perpendicular passes if anyone will act on a clearance; one pass justifies flags only.
  • Put the gates and the median lock in before the first drive, so numbers stay comparable across runs and vehicles.

Send the contact page your standoff, trunk width and threshold and we will match a camera to them, or work the camera configurator yourself — the mask math above runs unchanged on whatever camera meets the pixel budget.

Questions

Does the PCA angle need a calibrated camera?

No. The angle uses pixel coordinates only, so an uncalibrated phone or board camera is fine as long as the lens keeps straight lines straight. Keep the trunk inside the central two-thirds of the frame and avoid fisheye optics: wide lenses bend verticals near the frame edges and bias the reading. Calibration only becomes necessary when you want true 3D lean from known camera angles.

What does a negative or near-90° angle from the atan2 mean?

Read the sign as the tip direction within the frame and take the absolute value as the lean: with y pointing down, the formula returns lean from vertical directly. A result near ±90° means σyy − σxx went negative, so the mask is wider than it is tall — exactly the failure the elongation gate exists to catch. Fix the segmentation and re-run.

Which lean threshold should I flag at?

Utilities set their own limits; there is no industry standard. Published resilience work brackets healthy below about 15° and critical from 15° to 25°. For a single-camera drive-by that under-reads out-of-plane lean, a workable policy is to flag at your threshold, send everything from 10° up to review, and clear a pole only on two passes about 90° apart.

Can one image tell which way a pole is leaning?

No. One view gives the in-plane magnitude and the left-right tip within the frame; the azimuth of the lean stays unknown, and a pole tipping straight toward the vehicle reads near zero. Two passes at roughly right angles, or cameras on both sides of the vehicle, bracket the direction well enough to prioritize a follow-up inspection.

Does this work on concrete, steel or composite poles?

Yes. PCA needs only a cleanly segmented trunk, so the material does not matter to the math. It changes the segmentation risk: smooth concrete and steel glare and fray mask edges, so polarized or angled lighting helps, and lattice or hollow structures merge with the background, which is when you tighten the elongation gate.