LeadsByMail
A pipeline that turns building footprints, aerial imagery and terrain into a 3D scene, then uses that structure to guide property visualizations and printed mailers.
A personalized image needs more than a prompt
LeadsByMail explores a difficult reconstruction problem: an overhead image can show a roof and yard, but a street-level image needs a facade, height, camera position, materials and surroundings. The goal is a house image recognizable enough to anchor a personalized physical mailer. That goal makes geometry and evidence gathering part of the product. A visually attractive generic house would miss the point, so the pipeline tries to preserve footprint shape, roofline and site context before asking an image model to fill in appearance.
The resulting project is broader than an API wrapper. It has data-provider abstractions, footprint scoring, terrain and camera calculations, headless 3D rendering, vegetation and ground-feature detection, temporal comparison, generation constraints and PDF batching. Its most interesting learning story is the coordination of those tools. The fresh demonstration starts from a deliberately drawn synthetic aerial diagram, not a real satellite photo or an AI-generated house. It shows which engineering stages actually execute while keeping the harder question of real-house reconstruction separate from a successful local pipeline run.

Gather different kinds of evidence without pretending they agree
The source begins with an address and a geocoded location, then combines information with different strengths. OSM and Overture can supply building and road geometry; parcel or local records can contribute building attributes; imagery provides spatial context; elevation supplies the ground beneath the scene. Property collection launches independent lookups in parallel and records source/quality metadata. That metadata matters because a height tag, a story count and a footprint-based guess are different kinds of evidence even when each becomes a number in the same property dictionary.
Imagery and elevation are abstracted behind provider interfaces with retries and fallback chains. The default imagery chain names NAIP then TNM orthoimagery; elevation tries 3DEP resolutions in order. An SRTM class exists but explicitly remains unimplemented, so its presence is not a global-coverage achievement. Persistent caching reduces repeated fetches. The offline demonstration bypassed these external retrievals and substituted known synthetic inputs. What it verifies is the downstream handling of those inputs, while the provider architecture explains how the intended address-driven workflow would obtain them.
Choose a footprint before building a house from it
A flawed footprint can contaminate every later stage. The geometry module checks topology, removes repeated consecutive coordinates and can use Shapely repair operations before computing dimensions, area and shape. Footprint selection compares source quality instead of blindly accepting the first response. The quality and height modules also retain confidence and method information. That makes uncertainty inspectable: an estimated building height derived from levels or property stories should not masquerade as a surveyed measurement.
The renderer converts latitude/longitude into a local meter frame, then constructs walls and roof geometry from the footprint. Hip, gable and flat variants were all exercised in the fresh run, alongside a taller synthetic building. These are intentionally geometric references for later conditioning, not finished architectural models. The synthetic footprint's dimensions and area were computed by actual source, and an invalid two-point footprint returned no valid polygon. Together, the outputs demonstrate the foundation of the reconstruction workflow: make the physical scale and silhouette explicit before adding appearance.




Put the building on ground and the camera somewhere plausible
Terrain and viewpoint are part of fidelity. Raster elevation becomes a terrain mesh, while imagery is aligned through the project's coordinate transforms and texture coordinates. Roads, sidewalks and other site geometry share the local frame. Buildings and foreground objects must meet that ground rather than float above it or disappear into it. The validation module contains deterministic checks for issues such as driveway slope, roof pitch and foundation grounding, providing a different kind of evidence from an image model's visual judgment.
Camera selection uses road geometry and building position rather than a single arbitrary view. The implementation projects onto road segments, applies distance thresholds, shifts toward the curb/yard and includes framing/clipping adjustments for building scale. The demonstration used an actual generated GeoTIFF elevation raster with synthetic values, plus road and neighbor geometry, and ran the real rendering functions across several roofs and heights. The tall-building output is useful as a camera/framing exercise. It does not establish a measured building or a faithful facade; it makes otherwise hidden scene assumptions visible.

Trees and driveways are structural context
A house without its surroundings can be difficult to recognize. The tree detector combines vegetation cues with exclusion masks so buildings and roads do not become tree candidates. Its more elaborate path can use depth information, while a fallback uses HSV/green evidence, morphology and blob splitting. Detected canopy size becomes an estimated tree form for the 3D scene. Those heights are heuristic outputs, not measured arboricultural data. The illustrated example uses the HSV fallback on a sample diagram.
Ground-feature detection is another two-stage problem. Color filtering identifies candidate concrete/asphalt-like blobs outside building and road masks; geometric inference connects and classifies those surfaces as driveways or paths. The renderer can then place the resulting polygons into the same world as the building and terrain. Debug overlays show what was actually detected or inferred before it becomes a convincing-looking scene. This is a useful portfolio distinction: the line between observed pixels, inferred connectivity and final geometry stays visible instead of disappearing behind the finished image.



Compare dates only after aligning them
Multi-date imagery offers a way to separate stable structures from transient observations, but two images of the same area do not necessarily line up. The temporal module first estimates translation through phase cross-correlation, then shifts the moving image channel by channel. A later stage computes variance and a stability map. Feature matching can use position and size to support confidence across dates. Registration and change interpretation are separate operations; comparing unaligned pixels would confuse motion of the image with change in the property.
For the local demonstration, the second image was made by shifting the same synthetic diagram. The real registration function recovered the inverse shift, and the aligned pair produced an all-stable map. That white output is meaningful only within the fixture: it is an identity-style check, not evidence that real satellite histories are perfectly stable or that seasonal changes are solved. The broader source includes date retrieval and temporal confidence integration, while this capture intentionally exercises just the deterministic alignment/comparison stages without requesting external imagery.


Know what an overhead image cannot tell you
The source tackles appearance through several levels of evidence. Material detection prefers available records, examines roof pixels and can call a vision model for additional classification. Neighborhood-style clustering and surroundings descriptions supply context, but they remain inference rather than confirmation of an individual facade. Mapillary integration distinguishes a close direct view, a more distant style reference and a satellite-only case. Prompt construction adapts to those tiers so a neighboring building's appearance is not automatically treated as the target house's own measured detail.
A roof outline tells us more about a building’s shape than its windows, trim or wall material. The 3D stage supplies structure for the later appearance-generation step. The examples show that intermediate geometry using a sample property, rather than a finished photographic reconstruction.
Condition, inspect and retry with a specific reason
Generation uses more than a free-form description. The code assembles footprint dimensions, silhouette/reference renders, satellite observations, material and surroundings sections, and optional facade references. Masks and overlays provide additional spatial constraints. A separate validation call scores shape, vegetation, architectural consistency and appearance against the available references. Retry text is built from the weakest categories so a failed attempt can receive a targeted correction rather than the same prompt again.
Deterministic physics checks sit before that expensive step, and the orchestration records generation/validation attempts and verdicts. This gives the pipeline useful intermediate artifacts for diagnosing whether a bad result began in data, geometry or the generative stage. The source establishes the intended model integration, not a freshly verified level of real-house fidelity. In this local run, a rendered PNG was temporarily placed at the filename expected by PDF production solely to exercise layout. That filename does not turn it into a successful AI generation, and the gallery identifies it as a synthetic 3D render wherever it appears on a mailer.


Carry the image into something that can be held
The PDF layer turns an image and address components into front/back mail pieces. The source provides postcard and flyer dimensions, headline placement, address/postage areas, optional back templates and image upsampling for a target output density. The fresh run produced two-page examples at 6-by-4 inches, 9-by-6 inches and 8.5-by-11 inches. The landscape-to-portrait difference is worth showing because it changes the use of the same source image. The synthetic address and placeholder advertiser areas keep the examples clearly separate from an actual campaign.
Physical output also exposes a documentation mismatch. The module header describes bleed-extended formats, but the current per-address implementation creates trim-size canvases. Direct inspection found the example PDFs and current batch PDFs resolve MediaBox, TrimBox and BleedBox to the trim dimensions, without additional bleed. The honest claim is working layout generation, not certified print-shop compliance. Image upsampling similarly changes the raster size without proving recovered detail, and barcode generation was disabled for this fixture. Actual PDF files and the measured box report are linked so those boundaries can be checked.




A campaign needs a production record
Batch production discovers successful address folders, checks required image/geocode inputs and groups records by three-digit ZIP prefix. It generates address PDFs, collects skipped/included outcomes and writes a CSV manifest. The current source separates backs from fronts and reverses front order for the documented manual-duplex stack workflow. Processing one group at a time also avoids one ever-growing global PDF writer. A dry run lets an operator inspect intended grouping and missing inputs before producing the files.
The synthetic run exercised discovery, two prefix groups, PDF production and archival of the synthetic input folders. That is useful proof of file-flow behavior, not evidence of postal delivery or campaign volume. The manifest uses a logical group filename while the actual generated files have front/back suffixes; the downloadable examples preserve that distinction. Both synthetic folders reused the same dummy geocode payload, so this exercise should not be used to claim complete recipient-to-mail-piece matching. It verifies the selected batching mechanics and makes the next production checks concrete.
Make a long pipeline inspectable and restartable
The main orchestration is designed around address-sized units of work. It builds an existing-output index, limits batches, dispatches work through a thread pool and updates a checkpoint after each completed future. Checkpoint writes use a lock and temporary-file replacement. Resume reads the stored handled sets before scheduling more work, while per-stage caching and retained intermediate artifacts reduce the need to start the entire investigation over. These are practical concerns once external retrieval, rendering and model calls share a pipeline.
There are also limits to what source structure proves. A future completing without an exception is the criterion used by the outer runner's success counter; this is not automatically the same as a high-quality generated image. Resume excludes both recorded processed and failed addresses, so retry policy deserves explicit attention rather than a blanket fault-tolerance claim. The fresh harness ran selected stages in isolation with network access blocked, not the credentialed full main entry point. Its report identifies exactly which functions ran and leaves provider availability, paid validation and large-volume behavior outside the demonstrated result.
The later idea changes the input, not just the screen
The May roadmap proposes a Door-to-Door Companion: a rep supplies an actual house photo and receives a service-specific after-image with a comparison view. That changes the reconstruction problem. If the rep already has a facade photograph, there is less reason to infer it from overhead imagery. The planned FastAPI/Flutter flow shares generation infrastructure but is explicitly separate from the satellite/3D postcard path. Planning records include camera, address confirmation, disclosure, budgets and physical-device acceptance considerations; they do not establish that the seven-phase app was delivered.
Across both directions, the source-supported learning topics are clear: reconcile uncertain inputs, keep geometry in a common coordinate frame, expose what a detector observed, distinguish a model-generated impression from a verified fact, and inspect the physical output rather than trusting a docstring. Joey-authored history supports the provider/geometry/vision/temporal/print work, while current local changes add another uncommitted layer that must remain qualified. The project deserves a full story because it connects programming to image-making and physical production through intermediate artifacts that can actually be examined.