diff --git a/apps/api/src/autopilot/bursts.ts b/apps/api/src/autopilot/bursts.ts index 869f58f..84f48cc 100644 --- a/apps/api/src/autopilot/bursts.ts +++ b/apps/api/src/autopilot/bursts.ts @@ -42,6 +42,25 @@ export function groupBursts(frames: F[], gapMs: number): F[][] return [...bursts, ...loose].sort((a, b) => (a[0]!.capturedAt?.getTime() ?? 0) - (b[0]!.capturedAt?.getTime() ?? 0)); } +/** A good reportage sequence can yield several plans. More than this of one moment is too many. */ +export const REPORTAGE_SEQUENCE_CAP = 3; +/** + * Variance of the Laplacian at 1024 px above this is a sharp frame. A sequence needs three such frames before + * it is worth more picks than the event asked for. + */ +export const FOCUS_SHARP = 120; + +/** + * How many frames of a reportage burst to keep. An ordinary sequence stays at `configured`. A sharp one (three + * or more frames in focus) may go up to three, so the same moment can be a full body, a half body and a + * three-quarter. Never more than three, and never any when the event asked for none. + */ +export function reportagePickCount(sharpFrames: number, configured: number): number { + if (configured <= 0) return 0; + if (sharpFrames >= REPORTAGE_SEQUENCE_CAP) return REPORTAGE_SEQUENCE_CAP; + return configured; +} + /** * The best `n` frames of a burst: highest score first; on a near tie (within 3%), the earlier frame (usually the * peak of the action). Returned in capture order. diff --git a/apps/api/src/autopilot/service.ts b/apps/api/src/autopilot/service.ts index 63c708d..8d3a635 100644 --- a/apps/api/src/autopilot/service.ts +++ b/apps/api/src/autopilot/service.ts @@ -4,7 +4,7 @@ import type { Db } from "../db.js"; import type { DeliveryService } from "../delivery/service.js"; import type { RenderEngine } from "../develop/engine.js"; import type { DevelopService } from "../develop/service.js"; -import { type Box, compose, frameScore, minCropWidth, peopleIn } from "../composition/compose.js"; +import { type Box, compose, frameScore, isReportage, minCropWidth, peopleIn, planCrop } from "../composition/compose.js"; import type { SubjectDetector } from "../composition/detect.js"; import { constrainRotated, tighter } from "../composition/geometry.js"; import type { IngestLogger } from "../ingest/service.js"; @@ -15,7 +15,7 @@ import { focusFromExifJson } from "../ingest/focus.js"; import { readFocusPoint } from "../ingest/exif.js"; import { CANDIDATE_SELECT, candidatesOf } from "./best.js"; import { sequenceWeights } from "./sequence.js"; -import { bestOf, groupBursts } from "./bursts.js"; +import { bestOf, FOCUS_SHARP, groupBursts, reportagePickCount } from "./bursts.js"; import { curate, matchMinutes } from "./curate.js"; import { type LearntStyle, learntStyle, TONE_KEYS, WB_KEYS } from "./learning.js"; import { lookValues } from "./look.js"; @@ -44,6 +44,12 @@ export interface AutopilotRecord { picked?: boolean; /** People in the subject (a duel, a celebration). */ people?: number; + /** "reportage" keeps a whole person; "sport" is a ball in play. */ + context?: "sport" | "reportage"; + /** Laplacian variance of the subject, for telling a sharp sequence from a blurred one. */ + focus?: number; + /** Half-body and three-quarter crops, used when a reportage sequence is sharp enough for more than one plan. */ + plans?: { half: Box | null; threeQuarter: Box | null } | null; /** "Only the best": set when the photo's window was decided, and whether it went into the gallery. */ curated?: boolean; chosen?: boolean; @@ -92,7 +98,7 @@ export class AutopilotService { async process(photoId: string): Promise { const { db, storage, log, develop, engine } = this.deps; try { - const photo = await db.photo.findUniqueOrThrow({ where: { id: photoId }, include: { event: { select: { autopilot: true, createdById: true, venue: true } } } }); + const photo = await db.photo.findUniqueOrThrow({ where: { id: photoId }, include: { event: { select: { autopilot: true, createdById: true, venue: true, away: true, fixtureId: true } } } }); const settings = AutopilotSettings.parse(photo.event?.autopilot ?? {}); if (!settings.enabled) { await db.photo.update({ where: { id: photoId }, data: { autopilotStatus: "NONE" } }); @@ -129,8 +135,11 @@ export class AutopilotService { const focusFile = photo.originalStored ? storage.resolve(photo.storageKey) : preview; const focus = focusFromExifJson(photo.exif) ?? (existsSync(focusFile) ? await readFocusPoint(focusFile) : null); const minWidth = minCropWidth(W, H, settings.minLongEdge); - const composition = detections ? compose(detections, aspect, { minWidth, focus, framing: settings.framing }) : null; - const wideComposition = detections && settings.framing === "tight" ? compose(detections, aspect, { minWidth, focus, framing: "full" }) : null; + const reportage = isReportage(photo.event); + const context = reportage ? "reportage" : "sport"; + const composition = detections ? compose(detections, aspect, { minWidth, focus, framing: settings.framing, context }) : null; + const wideComposition = detections && !reportage && settings.framing === "tight" ? compose(detections, aspect, { minWidth, focus, framing: "full", context: "sport" }) : null; + const plans = reportage && detections ? { half: planCrop(detections, "half", aspect, { minWidth, focus }), threeQuarter: planCrop(detections, "threeQuarter", aspect, { minWidth, focus }) } : null; let crop: Box | null = null; if (settings.crop && composition) { // Photographers who always tighten the autopilot's crop get it tighter (never cutting into the subject). @@ -160,6 +169,9 @@ export class AutopilotService { crop, wide, angle, + context, + focus: subjectFocus(detections, composition?.subject ?? null), + plans, style: style && (Object.keys(style.offsets).length || style.cropFactor) ? style : null, }; await db.photo.update({ where: { id: photoId }, data: { autopilotStatus: "DONE", autopilot: record as object } }); @@ -181,7 +193,7 @@ export class AutopilotService { WHERE autopilot_status = 'DONE' AND event_id IS NOT NULL AND (autopilot->>'decided') IS NULL`; let picked = 0; for (const { event_id: eventId } of undecided) { - const event = await db.event.findUnique({ where: { id: eventId }, select: { id: true, organizationId: true, autopilot: true, createdById: true } }); + const event = await db.event.findUnique({ where: { id: eventId }, select: { id: true, organizationId: true, autopilot: true, createdById: true, away: true, fixtureId: true } }); if (!event) continue; const settings = AutopilotSettings.parse(event.autopilot ?? {}); const busy = await db.photo.count({ where: { eventId, autopilotStatus: { in: ["PENDING", "RUNNING"] } } }); @@ -205,27 +217,60 @@ export class AutopilotService { if (burst.every((f) => f.rec?.decided)) continue; // Still arriving: wait until the burst has settled. if (Math.max(...burst.map((f) => f.createdAt.getTime())) > now.getTime() - BURST_SETTLE_MS) continue; - const best = bestOf(burst, settings.picksPerBurst); + const reportage = isReportage(event); + const sharp = burst.filter((f) => (f.rec?.focus ?? 0) >= FOCUS_SHARP).length; + const asked = reportage ? reportagePickCount(sharp, settings.picksPerBurst) : settings.picksPerBurst; + const planKey = [null, "half", "threeQuarter"] as const; + // Extra frames beyond the event's number are only kept when they can carry a different plan. + // The plan stays with the frame: dropping one does not hand its crop to the next. + const chosen = bestOf(burst, asked) + .map((f, i) => ({ f, key: planKey[i] ?? null })) + .filter(({ f, key }, i) => { + if (!reportage || i < settings.picksPerBurst) return true; + const planned = key ? f.rec?.plans?.[key] : null; + return !!planned && !!f.rec?.crop && distinctPlan(f.rec.crop, planned); + }); + const best = chosen.map((c) => c.f); const toFlag = best.filter((f) => f.flag === "NONE").map((f) => f.id); if (toFlag.length) { await db.photo.updateMany({ where: { id: { in: toFlag } }, data: { flag: "PICK" } }); broadcaster.library(event.organizationId, { type: "photo.updated", ids: toFlag, patch: { flag: "PICK" } }); picked += toFlag.length; } - // Variety: the second pick gets the other framing. A tight first pick: the wider, whole-body frame (the - // context the agencies mix in); otherwise a slightly tighter one. - const second = best[1]; - const secondEdited = second ? await db.photoEdit.count({ where: { photoId: second.id, NOT: { clientId: "autopilot" } } }) : 0; - const crop2 = second?.rec?.crop; - const wider = crop2 && second.rec?.wide && (second.rec.wide.x1 - second.rec.wide.x0) / (crop2.x1 - crop2.x0) > 1.12 ? second.rec.wide : null; - if (crop2 && second.rec?.subject && settings.crop && !secondEdited) { - const rect = wider ?? constrainRotated(tighter(crop2, second.rec.subject, 0.88), second.rec.angle, second.width ?? 3, second.height ?? 2); - await develop - .append(second.id, second.uploaderId ?? event.createdById ?? null, { - clientId: "autopilot", - ops: [{ opId: `autopilot-${second.id}-variant`, command: { command: "crop.set", params: { rect, angle: second.rec.angle, aspect: settings.aspect ?? [second.width ?? 3, second.height ?? 2] } } as EditCommand }], - }) - .catch((err: unknown) => log.warn({ err }, "autopilot: variant crop failed")); + if (reportage) { + // A sharp sequence: the second frame is a half body, the third a three-quarter. The first keeps the + // whole person. A plan that cannot be made (too small, or the same as the full crop) is skipped. + for (const { f: framePick, key } of chosen) { + if (!key) continue; + const planned = framePick.rec?.plans?.[key]; + const primary = framePick.rec?.crop; + if (!planned || !primary || !settings.crop || !distinctPlan(primary, planned)) continue; + const edited = await db.photoEdit.count({ where: { photoId: framePick.id, NOT: { clientId: "autopilot" } } }); + if (edited) continue; + const rect = constrainRotated(planned, framePick.rec?.angle ?? 0, framePick.width ?? 3, framePick.height ?? 2); + await develop + .append(framePick.id, framePick.uploaderId ?? event.createdById ?? null, { + clientId: "autopilot", + ops: [{ opId: `autopilot-${framePick.id}-plan-${key}`, command: { command: "crop.set", params: { rect, angle: framePick.rec?.angle ?? 0, aspect: settings.aspect ?? [framePick.width ?? 3, framePick.height ?? 2] } } as EditCommand }], + }) + .catch((err: unknown) => log.warn({ err }, "autopilot: plan crop failed")); + } + } else { + // Variety: the second pick gets the other framing. A tight first pick: the wider, whole-body frame (the + // context the agencies mix in); otherwise a slightly tighter one. + const second = best[1]; + const secondEdited = second ? await db.photoEdit.count({ where: { photoId: second.id, NOT: { clientId: "autopilot" } } }) : 0; + const crop2 = second?.rec?.crop; + const wider = crop2 && second.rec?.wide && (second.rec.wide.x1 - second.rec.wide.x0) / (crop2.x1 - crop2.x0) > 1.12 ? second.rec.wide : null; + if (crop2 && second.rec?.subject && settings.crop && !secondEdited) { + const rect = wider ?? constrainRotated(tighter(crop2, second.rec.subject, 0.88), second.rec.angle, second.width ?? 3, second.height ?? 2); + await develop + .append(second.id, second.uploaderId ?? event.createdById ?? null, { + clientId: "autopilot", + ops: [{ opId: `autopilot-${second.id}-variant`, command: { command: "crop.set", params: { rect, angle: second.rec.angle, aspect: settings.aspect ?? [second.width ?? 3, second.height ?? 2] } } as EditCommand }], + }) + .catch((err: unknown) => log.warn({ err }, "autopilot: variant crop failed")); + } } const pickedIds = new Set(best.map((f) => f.id)); for (const f of burst) { @@ -320,6 +365,21 @@ export function restOf(ids: readonly string[], chosen: ReadonlySet, flag return ids.filter((id) => !chosen.has(id) && flags.get(id) === "PICK"); } +function subjectFocus(d: { people: { x0: number; y0: number; x1: number; y1: number; focus?: number }[] } | null, subject: Box | null): number { + if (!d || !subject) return 0; + const values = d.people + .filter((p) => p.x0 >= subject.x0 - 1e-9 && p.x1 <= subject.x1 + 1e-9 && p.y0 >= subject.y0 - 1e-9 && p.y1 <= subject.y1 + 1e-9) + .map((p) => p.focus ?? 0); + return values.length ? Math.max(...values) : 0; +} + +/** A plan is worth applying when its height is clearly different from the crop already on the photo. */ +function distinctPlan(a: Box, b: Box): boolean { + const ah = a.y1 - a.y0; + const bh = b.y1 - b.y0; + return Math.abs(ah - bh) / Math.max(ah, bh, 1e-6) > 0.12; +} + /** Polls the autopilot queue and settles bursts. */ export class AutopilotWorker { private timer: ReturnType | undefined; diff --git a/apps/api/src/composition/compose.ts b/apps/api/src/composition/compose.ts index a280b7f..f552c11 100644 --- a/apps/api/src/composition/compose.ts +++ b/apps/api/src/composition/compose.ts @@ -9,10 +9,10 @@ * body a little above the middle and little or no empty pitch under the feet (spare height goes above, to the * crowd and the stands). A foot that is whole in the photo stays in; heads and the ball are never cut. * - Cutting another sharp person in half is avoided; cutting blurred ones doesn't matter. - * - "tight" framing (the agencies' handball look: kolektiff images, measured on 600 photos of 2025-26): the - * subject fills the height and the face is big (about a seventh of the frame) near the top. A foot that is - * whole in the photo stays in; mid-shin or mid-thigh only when the frame does not finish the body. - * "full" keeps whole bodies when they fit (Peter's usual two thirds of the frame). + * - A generic event, and any photo with no ball, is reportage: a whole hand and a whole foot stay in. A leg is + * cut only when the foot already leaves the photo. A stray hand or foot of someone else is cropped out. + * - "tight" is the agencies' handball look, and only with a ball in play: the subject fills the height, cut + * mid-shin or mid-thigh when the foot is already out. "full" keeps whole bodies when they fit. * * Boxes are fractions of the upright photo (0..1, y down). * When the camera wrote a focus point, the person under it is the subject; sharpness still frames everyone else. @@ -74,6 +74,8 @@ export const TUNING = { belowMax: 0.08, wCut: 1.2, wJoint: 0.8, + /** A hand or a foot of someone who is not the subject, left in the frame. */ + wStray: 4, }; /** @@ -92,6 +94,10 @@ const MID_THIGH = 0.64; /** Ground kept under a sole that stays in the crop, as a fraction of the body height. */ const SOLE_PAD = 0.03; const SOLE_LIMIT = 0.995; +/** Deliberate plans of one moment: half body (between neck and hips) and three-quarter (mid-thigh). Never a joint, never the foot. */ +export const PLANS = { half: 0.42, threeQuarter: MID_THIGH } as const; +/** A non-subject shorter than this, against the photo edge, is a stray hand or foot, not another person. */ +const STRAY_HEIGHT = 0.35; /** Tight framing: the subject's tallest body about this many crop heights (a little cut at the bottom). */ export const TIGHT = { fillAt: 1.05, wFill: 2.2, chestAt: 0.34, headMax: 0.2 }; @@ -99,12 +105,24 @@ export const TIGHT = { fillAt: 1.05, wFill: 2.2, chestAt: 0.34, headMax: 0.2 }; export interface ComposeOptions { /** "full": whole bodies when they fit (default); "tight": the agencies' close framing. A complete foot stays in. */ framing?: "full" | "tight"; + /** + * "reportage": a person, no match (a generic event, or a photo with no ball). Whole hands and feet stay. + * "sport": a ball in play; tight framing may cut a leg only when the foot already leaves the photo. + */ + context?: "sport" | "reportage"; /** Narrowest crop allowed, as a fraction of the photo's width (from the delivery's minimum resolution). */ minWidth?: number; /** Where the camera focused. The person there is the subject; the rest of the crop still follows the model. */ focus?: FocusHint | null; } +/** A generic event: no opponent and no fixture. The crop is a person, not a match. */ +export function isReportage(event: { away?: string | null; fixtureId?: string | null } | null): boolean { + if (!event) return false; + if (event.fixtureId) return false; + return !(event.away ?? "").trim(); +} + const h = (b: Box) => b.y1 - b.y0; const w = (b: Box) => b.x1 - b.x0; const cx = (b: Box) => (b.x0 + b.x1) / 2; @@ -190,7 +208,10 @@ export function compose(d: Detections, aspect: number | null = null, opts: Compo const feetIn = s.y1 < FEET_IN_FRAME; // A little ground under a sole that is whole in the photo, so the crop line is not the shoe. const sole = feetIn ? Math.min(SOLE_LIMIT, s.y1 + Math.min(SOLE_PAD * tallest, Math.max(0, SOLE_LIMIT - s.y1))) : s.y1; - if (opts.framing === "tight") { + // A person, not a ball: reportage, or a match photo where nobody is playing the ball. The sports cut stays + // for a ball in play. A complete hand or foot is never cut just to fill the frame. + const personStory = opts.context === "reportage" || !ball; + if (opts.framing === "tight" && !personStory) { // The ball (and the hands on it) is never cut: the bottom edge stays below it. const keep = (y: number) => Math.min(s.y1, Math.max(y, ball ? ball.y1 + 0.01 : 0)); // Feet that are whole in the photo stay in. Mid-shin and mid-thigh are only for a body the frame does @@ -218,7 +239,7 @@ export function minCropWidth(width: number, height: number, minLongEdge = 2400): return Math.min(1, Math.max(0.35, minLongEdge / long) * (width >= height ? 1 : height / width)); } -function frame(s: Box, ratio: number, mustBottom: number, headroom: number, tallest: number, others: Detection[], inSubject: Detection[], reason: Composition["reason"], minWidth: number, tight = false): (Composition & { cost: number }) | null { +function frame(s: Box, ratio: number, mustBottom: number, headroom: number, tallest: number, others: Detection[], inSubject: Detection[], reason: Composition["reason"], minWidth: number, tight = false, pinBottom = false): (Composition & { cost: number }) | null { const mainSharp = Math.max(...inSubject.map(sharp)); let best: { rect: Box; cost: number } | null = null; for (let k = 0.35; k <= 1.0001; k += 0.025) { @@ -236,10 +257,15 @@ function frame(s: Box, ratio: number, mustBottom: number, headroom: number, tall const spare = Math.max(0, ch - (mustBottom - top)); for (let i = 0; i <= 24; i++) { const x0 = Math.min(Math.max(0, s.x1 - cw + (i / 24) * (cw - w(s))), 1 - cw); - for (let j = 0; j <= 20; j++) { - const y0 = Math.min(Math.max(0, top - (j / 20) * spare), 1 - ch); + // A plan pins the bottom on the waist or the thigh. Spare height goes above the head, never down into the legs. + const rows = pinBottom ? 1 : 21; + for (let j = 0; j < rows; j++) { + const y0 = pinBottom ? mustBottom - ch : Math.min(Math.max(0, top - (j / 20) * spare), 1 - ch); + if (y0 < -1e-9) continue; const r = { x0, y0, x1: x0 + cw, y1: y0 + ch }; + if (r.y1 > 1 + 1e-6) continue; if (r.x0 > s.x0 + 1e-6 || r.x1 < s.x1 - 1e-6 || r.y0 > Math.max(0, s.y0 - headroom) + 1e-6 || r.y1 < mustBottom - 1e-6) continue; + if (pinBottom && r.y1 > mustBottom + 0.02) continue; if (cutsFoot(r, inSubject)) continue; const c = cost(r, s, others, ch, tallest, mainSharp, ratio, inSubject, tight) + jointCost(r, inSubject, others, mainSharp); if (!best || c < best.cost) best = { rect: r, cost: c }; @@ -255,6 +281,12 @@ function cost(r: Box, s: Box, others: Detection[], ch: number, tallest: number, // Sharp people cut in half by the crop's edge look wrong; blurred ones (foreground, background) don't matter. for (const p of others) { const f = overlap(r, p) / Math.max(area(p), 1e-9); + // Only a hand or a foot of someone who is not being photographed: leave it out. A whole other person stays + // on the rule below (in, or out, never sliced). + if (strayLimb(p, tallest)) { + if (f > 0.02) c += TUNING.wStray * f; + continue; + } if (f <= 0.03 || f >= 0.95) continue; const focus = Math.min(1, sharp(p) / Math.max(mainSharp, 1e-6)); if (focus < TUNING.inFocus) continue; @@ -300,6 +332,33 @@ function cutsFoot(r: Box, people: Detection[]): boolean { return false; } +/** A short box against the photo edge: a hand or a foot of someone who is not the subject. */ +function strayLimb(p: Detection, tallest: number): boolean { + if (h(p) >= STRAY_HEIGHT * tallest) return false; + return p.x0 < 0.02 || p.x1 > 0.98 || p.y0 < 0.02 || p.y1 > 0.98; +} + +/** + * A second or third plan of the same moment (half body, three-quarter). The bottom sits mid-limb, the head and + * the hands inside the subject box stay, and the foot is not where the cut falls. Null when that plan cannot + * keep the delivery's resolution. + */ +export function planCrop(d: Detections, which: keyof typeof PLANS, aspect: number | null = null, opts: ComposeOptions = {}): Box | null { + const found = findSubject(d, opts.focus); + if (!found) return null; + const { box: s, reason, people: inSubject } = found; + const tallest = Math.max(...inSubject.map(h)); + const at = PLANS[which]; + if (at > FOOT_ZONE || JOINTS.some((j) => Math.abs(at - j) < JOINT_BAND)) return null; + const bottom = s.y0 + at * tallest; + const ratio = (aspect ?? d.width / d.height) * (d.height / d.width); + const others = d.people.filter((p) => p.score >= MIN_PERSON && !inSubject.includes(p)); + const made = frame(s, ratio, bottom, 0.04 * tallest, tallest, others, inSubject, reason, opts.minWidth ?? 0, true, true); + if (!made) return null; + if (made.rect.y1 > bottom + 0.025) return null; + return made.rect; +} + /** Crop edges that cross a body at a joint (ankle, knee, hip, neck): the "amputation" look. */ function jointCost(r: Box, subject: Detection[], others: Detection[], mainSharp: number): number { let c = 0; diff --git a/apps/api/test/autopilot.test.ts b/apps/api/test/autopilot.test.ts index 13d3ff1..db2158c 100644 --- a/apps/api/test/autopilot.test.ts +++ b/apps/api/test/autopilot.test.ts @@ -4,7 +4,7 @@ import path from "node:path"; import sharp from "sharp"; import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { AutopilotService } from "../src/autopilot/service.js"; -import { bestOf, groupBursts } from "../src/autopilot/bursts.js"; +import { bestOf, groupBursts, reportagePickCount } from "../src/autopilot/bursts.js"; import { type Candidate, actionScore, curate } from "../src/autopilot/curate.js"; import { correctionOf, fold, learntStyle, recordCorrection, styleOf } from "../src/autopilot/learning.js"; import type { Detections } from "../src/composition/compose.js"; @@ -55,6 +55,13 @@ describe("bursts", () => { expect(bestOf(burst, 2).map((x) => x.id)).toEqual(["b", "c"]); expect(bestOf(burst, 0)).toEqual([]); }); + it("keeps up to three frames of a sharp reportage sequence, and the event's number otherwise", () => { + expect(reportagePickCount(4, 2)).toBe(3); + expect(reportagePickCount(3, 1)).toBe(3); + expect(reportagePickCount(2, 2)).toBe(2); + expect(reportagePickCount(6, 5)).toBe(3); + expect(reportagePickCount(8, 0)).toBe(0); + }); }); describe("only the best", () => { diff --git a/apps/api/test/compose.test.ts b/apps/api/test/compose.test.ts index f6f4b92..4f2b098 100644 --- a/apps/api/test/compose.test.ts +++ b/apps/api/test/compose.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { compose, type Detection, findSubject, minCropWidth } from "../src/composition/compose.js"; +import { compose, type Detection, findSubject, isReportage, minCropWidth, planCrop } from "../src/composition/compose.js"; const person = (x0: number, y0: number, x1: number, y1: number, score = 0.9): Detection => ({ x0, y0, x1, y1, score }); const inside = (r: { x0: number; y0: number; x1: number; y1: number }, b: { x0: number; y0: number; x1: number; y1: number }) => r.x0 <= b.x0 + 1e-9 && r.y0 <= b.y0 + 1e-9 && r.x1 >= b.x1 - 1e-9 && r.y1 >= b.y1 - 1e-9; @@ -110,6 +110,14 @@ describe("tight framing (the agencies' handball look)", () => { expect(((tight.rect.x1 - tight.rect.x0) * 3000) / (hT * 2000)).toBeCloseTo(1.5, 2); }); + it("keeps a complete foot on a match photo that has no ball", () => { + const p = { ...person(0.42, 0.12, 0.58, 0.78), sharpness: 1 }; + const c = compose({ ...frame, people: [p], balls: [] }, null, { framing: "tight", context: "sport" })!; + expect(c.rect.y1).toBeGreaterThan(p.y1); + expect(c.rect.x0).toBeLessThanOrEqual(p.x0); + expect(c.rect.x1).toBeGreaterThanOrEqual(p.x1); + }); + it("keeps a ball held low, and the feet when they are in the photo", () => { const p = { ...person(0.42, 0.1, 0.56, 0.9), sharpness: 1 }; const ball = { x0: 0.5, y0: 0.7, x1: 0.54, y1: 0.76, score: 0.8 }; @@ -118,3 +126,47 @@ describe("tight framing (the agencies' handball look)", () => { expect(tight.rect.y1).toBeGreaterThan(p.y1); }); }); + +describe("reportage", () => { + it("is a generic event, and a match is not", () => { + expect(isReportage({ away: "", fixtureId: null })).toBe(true); + expect(isReportage({ away: " ", fixtureId: null })).toBe(true); + expect(isReportage({ away: "Sporting", fixtureId: null })).toBe(false); + expect(isReportage({ away: "", fixtureId: "11111111-1111-4111-8111-111111111111" })).toBe(false); + }); + + it("keeps the whole person when the event asked for the sports framing", () => { + const p = person(0.4, 0.15, 0.55, 0.8); + const c = compose({ ...frame, people: [p], balls: [] }, null, { framing: "tight", context: "reportage" })!; + expect(c.rect.y1).toBeGreaterThan(p.y1); + expect(c.rect.x0).toBeLessThanOrEqual(p.x0); + expect(c.rect.x1).toBeGreaterThanOrEqual(p.x1); + expect((p.y1 - p.y0) / (c.rect.y1 - c.rect.y0)).toBeLessThan(1); + }); + + it("leaves out a stray hand at the edge of someone who is not the subject", () => { + const subject = person(0.22, 0.18, 0.4, 0.82); + const hand = person(0, 0.35, 0.07, 0.5, 0.8); + const c = compose({ ...frame, people: [subject, hand], balls: [] }, null, { context: "reportage" })!; + const handIn = Math.max(0, Math.min(c.rect.x1, hand.x1) - Math.max(c.rect.x0, hand.x0)) / (hand.x1 - hand.x0); + expect(handIn).toBeLessThan(0.05); + expect(c.rect.y1).toBeGreaterThan(subject.y1); + }); + + it("makes a half-body plan above the hips and a three-quarter above the knee, head included", () => { + const p = person(0.4, 0.1, 0.55, 0.9); + const d = { ...frame, people: [p], balls: [] }; + const half = planCrop(d, "half")!; + const three = planCrop(d, "threeQuarter")!; + const at = (y: number) => (y - p.y0) / (p.y1 - p.y0); + expect(half.y0).toBeLessThanOrEqual(p.y0); + expect(half.x0).toBeLessThanOrEqual(p.x0); + expect(half.x1).toBeGreaterThanOrEqual(p.x1); + expect(at(half.y1)).toBeGreaterThan(0.35); + expect(at(half.y1)).toBeLessThan(0.5); + expect(at(three.y1)).toBeGreaterThan(0.58); + expect(at(three.y1)).toBeLessThan(0.72); + expect(half.y1).toBeLessThan(p.y1); + expect(three.y1).toBeLessThan(p.y1); + }); +}); diff --git a/docs/photo-editing-rules.md b/docs/photo-editing-rules.md index a2f0fce..66734f7 100644 --- a/docs/photo-editing-rules.md +++ b/docs/photo-editing-rules.md @@ -25,21 +25,26 @@ Following the AP and NPPA codes: everyone contesting it come along. Without one, the subject and the sharp people with them (a duel, a celebration, a line-up). - **Shape:** the photo's own aspect unless the event or the editor chose another (never turned vertical). -- **Framing** (per event): +- **Context:** a generic event (no opponent, no fixture) is reportage. A match is sport, and a photo of that + match with no ball in play is cropped as a person. Reportage does not use the handball cut. +- **Framing** (per event, sport only): - **"tight"** (default) is the agencies' handball framing, measured on kolektiff images (600 EHF/IHF photos of - 2025-26). The subject is about as tall as the crop, the legs are cut mid-shin or mid-thigh, and the face is - big (a median face of 14% of the frame height) near the top. Whole bodies are kept only when that frames - better. + 2025-26). With a ball in play, the subject is about as tall as the crop and a leg may be cut mid-shin or + mid-thigh when the foot already leaves the photo. The face is big (a median face of 14% of the frame height) + near the top. - **"full"** keeps whole bodies when they fit: Peter's usual crop, about two thirds of the frame. -- **Never cut:** heads, faces, hands holding the ball, the ball itself. + - **Reportage** always keeps a whole hand and a whole foot. The sports framing on the event is ignored. +- **Never cut:** heads, faces, a hand or a foot that is whole in the photo, hands holding the ball, the ball itself. - **Limbs:** if a body has to be cut, cut mid-limb (mid-thigh, mid-shin, mid-forearm), never at a joint (ankle, knee, hip, wrist, elbow, neck). The engine estimates joints from the body box and avoids crop edges there. -- **Feet:** a foot that is whole in the photo stays in the crop, with a little ground under the sole. Cutting - the shoe or the ankle is not a mid-limb cut. With "full", keep the whole body when it fits; otherwise cut - mid-thigh, never at the ankle. With "tight", the same: mid-shin or mid-thigh only when the frame does not - finish the body or the whole body cannot fit, and never below the ball. +- **Feet and hands:** a foot or a hand that is whole in the photo stays in the crop. A foot keeps a little + ground under the sole. Cutting the shoe, the ankle or a hand just to fill the frame is not allowed. A leg is + cut only when the foot already leaves the photo, or the whole body cannot fit: mid-thigh, or (with a ball in + play) mid-shin, never at a joint, and never below the ball. - **Edges:** no slivers of other in-focus people at the crop edge: either in, or out. Blurred foreground and background people don't count. +- **Stray limbs:** a hand or a foot of someone who is not the subject, and nothing more of them, is cropped out + so the frame stays clean. A whole other person is not that: they stay in or go out, they are not sliced. - **Headroom:** heads a little below the top edge, not touching it, not floating in empty space. - **Vertical placement:** the upper body (chest, faces) a little above the middle of the crop, never the knees. Little or no empty pitch or floor under the feet: when the crop is taller than the subject, the spare height @@ -66,9 +71,13 @@ A camera at 10–30 frames per second sends several photos of the same moment. is the only picture of that moment. - **Keep:** the best 1–2 frames per burst (configurable), flagged as picks. The rest stay unflagged (never rejected or deleted automatically). -- **Variety:** when two frames of a burst are kept, the second gets the other framing so the client has a choice. - After a tight first pick, the second gets the wider, whole-body frame with context, as Getty mixes in. - Otherwise the second is slightly tighter. +- **Reportage sequences:** when three or more frames of one moment are sharp, keep up to three (even if the + event asked for fewer) and give them different plans: whole body, half body, three-quarter. More than three + of the same moment is too many. The half and three-quarter cuts sit mid-limb, and only when the file still + has the delivery's resolution. A blurred sequence stays at the event's number. +- **Variety (sport):** when two frames of a burst are kept, the second gets the other framing so the client has + a choice. After a tight first pick, the second gets the wider, whole-body frame with context, as Getty mixes + in. Otherwise the second is slightly tighter. - **Saturation:** an event can cap how many picks one burst, or one minute of play, may produce, so a long attack doesn't flood the delivery. diff --git a/packages/contracts/src/library.ts b/packages/contracts/src/library.ts index f2f45c1..2fdcfa4 100644 --- a/packages/contracts/src/library.ts +++ b/packages/contracts/src/library.ts @@ -35,9 +35,9 @@ export const AutopilotSettings = z.object({ /** Neutral whites (white kits, the floor's lines), as the agencies deliver. */ whiteBalance: z.boolean().default(true), /** - * Crop framing: "tight", the agencies' close handball framing (subject fills the height, face near the top; - * a foot that is whole in the photo stays in, and the second pick of a burst gets the wider frame); "full", - * whole bodies when they fit. + * Crop framing for a match: "tight", the agencies' close handball framing (a ball in play; a foot that is whole + * stays in, and the second pick gets the wider frame); "full", whole bodies when they fit. A generic event is + * reportage and ignores this: whole hands and feet stay, and a sharp sequence can keep up to three plans. */ framing: z.enum(["tight", "full"]).default("tight"), /** Finishing look (apps/api/src/autopilot/look.ts): "agency" punchy kits, "natural" Getty-like, "none". */