Building practical AI
Deepak Kumar Tiwari

Deepak Kumar Tiwari

Technology & AI Leader · Building practical systems

Multimodal inspection / Guide 87

Fruit Video Quality Grading Must Count Fruit, Not Frames

Build fruit video quality grading packets that deduplicate tracks, preserve unseen surfaces, validate measured defect area, and keep lot decisions under human review.

Illustrative engineering guide. Examples are not client deployments, production-ready integrations, or evidence of measured results. Validate the design with your domain and security owners.

Reference workflow: Lot and video manifest; Fruit track candidates; Surface measurement; Unique coverage gate; Human grading review.
Reference workflow. Steps identify responsibilities, not necessarily separate agents. Branches and recovery paths are explained below. Open full-size diagram.

A hypothetical packing line records an apple rotating under a camera. Eight frames show the same brown patch, while the underside never becomes visible. A naive assistant reports eight defective apples and classifies the lot from those frame counts. Another version averages the eight predictions and calls the result high confidence. Both confuse repeated observations with independent inspected units.

The useful unit is a fruit instance with a documented surface-coverage record. Build advisory grading packets that connect candidate blemishes to that instance, retain measurement uncertainty, and mark unseen surfaces unknown. External appearance alone does not establish internal quality, microbial safety, temperature, or the cause of a mark. Commercial lot acceptance remains a human decision under the applicable grading procedure.

Establish Identity Across the Rotation

Record lot identifier, product specification revision, capture session, video digest, camera configuration, and presentation timestamps. Give each fruit a track identifier linked to conveyor position or another independently checked instance reference. A track identifier generated by a model is a hypothesis: merges and splits must remain detectable, especially when fruit touch or briefly disappear.

Store image coordinates in pixels from the upper-left corner. Define the fixture’s surface sectors relative to the fruit’s observed rotation, not the camera’s screen quadrants. Four screen corners do not prove that four physical sides were seen. Physical blemish area requires an appropriate calibrated surface measurement; an uncalibrated mask should remain a pixel-area observation.

The W3C provenance overview distinguishes source entities from derivation activities. Apply that structure to video, extracted frames, track association, surface mapping, and grading review. If a tracker merges two apples, correcting the association must also invalidate derived per-fruit statistics rather than leave an apparently authoritative grade attached to the old track.

Measure Surface Evidence Separately

The candidate generator can identify unusual color or texture regions. A specialist measurement stage determines whether those regions support a surface-area estimate under the capture geometry. OpenCV’s calibration tutorial describes lens distortion, camera parameters, and known object-point correspondences. Calibration helps establish scale, but a rotating curved fruit is not a flat calibration board.

Preserve scale, registration, and segmentation uncertainty separately. A blemish wrapping around the visible silhouette may have substantially uncertain area. NIST’s uncertainty guidance includes covariance when combining components. Repeated views under the same lighting and calibration share errors; their count is not a direct measure of confidence.

Use neutral intermediate labels such as “visible surface mark.” A language model can explain why a fruit needs review, but should not turn a color patch into a diagnosis of rot or attribute damage to a handler. Comparing calibrated measurements with a versioned buyer specification is deterministic software work, not a task that needs several agents voting over the same images.

Reproduce the Repeated-Frame Failure

This self-contained Python fixture tests the HARNESS on synthetic metadata and supplied area measurements. It does not evaluate a trained vision model, camera, tracker, or real inspection performance. Five required sectors, including the underside, and the area threshold are illustrative policy values, not an official fruit grading standard. No real media or engine API calls occur.

from math import isfinite

required = frozenset({"front", "back", "left", "right", "underside"})
base = dict(lot="LOT-6", spec=2, fruit="track-A", source="synthetic-video",
            frame="fruit-sectors-v1", time_ms=1000, sector="front",
            registration_mm=0.3, area_mm2=4.0, bound_mm2=1.0)
repeated = [dict(base, time_ms=1000 + i * 40) for i in range(8)]

def packet(rows):
    if not rows:
        return "abstain:no-evidence"
    sectors = set()
    upper = 0.0
    for r in rows:
        if (r["lot"], r["spec"], r["fruit"], r["frame"]) != (
                "LOT-6", 2, "track-A", "fruit-sectors-v1"):
            return "abstain:identity"
        if not r["source"] or not isfinite(r["time_ms"]) or not 0 <= r["time_ms"] <= 5000:
            return "abstain:provenance"
        if not all(isfinite(r[k]) and r[k] >= 0 for k in
                   ("registration_mm", "area_mm2", "bound_mm2")):
            return "abstain:measurement"
        if r["registration_mm"] > 1:
            return "abstain:registration"
        sectors.add(r["sector"])
        upper = max(upper, r["area_mm2"] + r["bound_mm2"])
    if not required <= sectors:
        return "recapture:surface"
    return "review-mark" if upper > 6 else "review-complete"

assert len(repeated) == 8 and packet(repeated) == "recapture:surface"
sides = [dict(base, sector=s) for s in ("front", "back", "left", "right")]
assert packet(sides) == "recapture:surface"
assert packet(sides + repeated) == "recapture:surface"
complete = sides + [dict(base, sector="underside")]
assert packet(complete) == "review-complete"
assert packet(complete + [dict(base, fruit="track-B")]) == "abstain:identity"
assert packet([dict(r, area_mm2=8) for r in complete]) == "review-mark"
assert packet([]) == "abstain:no-evidence"
for sector in required:
    assert packet([r for r in complete if r["sector"] != sector]) == "recapture:surface"
for invalid in (float("nan"), float("inf"), float("-inf")):
    assert packet([dict(r, time_ms=invalid) for r in complete]) == "abstain:provenance"
assert packet([dict(r, time_ms=0) for r in complete]) == "review-complete"
assert packet([dict(r, time_ms=5000) for r in complete]) == "review-complete"
print("fruit grading harness: synthetic assertions passed")

Eight repeated frames still leave the surface incomplete. Even four distinct side sectors cannot replace the required underside observation. Review completeness covers only the five named toy sectors, not a validated whole-fruit surface model. The fixture uses the largest supplied candidate-area upper bound rather than summing repeated measurements of the same mark. It does not calculate total blemish area across distinct marks. Production grading would need explicit mark identities, overlap handling, and a validated surface-coverage model before attempting that aggregation.

Make Unknown Fruit Visible in Lot Reports

Coverage has two denominators: planned fruit instances and required observed surface per instance. A report that grades only easy, fully visible apples can misrepresent the lot. Include merged tracks, missed instances, occluded surfaces, and unmeasurable marks in the lot accounting. Do not assign them a passing grade simply to keep a downstream dashboard complete.

The data-quality workflow provides the broader pattern of separating invalid records from valid business conclusions. The related package damage evidence exercise applies the same unseen-surface boundary to static photographs, where frame deduplication is less central but evidence association still matters.

Authorize lot access and review actions server-side, isolate tenant media, and treat label text or visible instructions as untrusted inputs. Avoid worker identity or productivity judgments from background footage. Crop or restrict unnecessary human imagery in review exports while retaining controlled originals according to the organization’s retention policy.

The example omits authentication, verified lot registries, real tracking, measurement calibration, durable state, approval records, transactions, and grading-system semantics. A human-approved recheck ticket should use lot, fruit association, evidence revision, and policy version as its idempotency scope. If a write times out, reconcile the authoritative ticket before retrying. A video-processing success flag is not a lot disposition receipt.

Acceptance Tests and Evaluation

  • Repeat one surface frame eight times; surface coverage and inspected-fruit count must not increase eightfold.
  • Merge two fruit tracks; block the combined packet until an association reviewer resolves the identity conflict.
  • Leave the underside unseen; report incomplete coverage even when all four side sectors are supplied and look ordinary.
  • Change the buyer specification revision; recompute advisory comparisons without altering earlier review history.
  • Supply a mark near the illustrative area boundary with a wide uncertainty bound; route it for review rather than hiding the bound.
  • Retry an approved recheck after an uncertain response; create no duplicate lot action.

Evaluate on independently captured lots with human-adjudicated fruit identities and surface coverage. Measure duplicate instance counts divided by true inspected instances, incomplete fruit labeled complete divided by all incomplete fruit, and reviewer disagreement per admitted packet. Keep track failures in the denominator. Split by lot and acquisition session, not adjacent video frames, because repeated views are correlated.

Start with advisory packets for one fruit type under one capture setup. Compare reviewer effort and coverage mistakes against manual video review before extending to new varieties or lighting. AI systems engineering should first prove instance accounting and unknown-state handling. Faster grading language is not useful if the system cannot tell one repeatedly filmed apple from eight different apples.

Sources