From 88cd74f5ff0132f218a59e63268c9111909d9e6a Mon Sep 17 00:00:00 2001 From: spark Date: Mon, 23 Nov 2026 13:44:22 +0000 Subject: [PATCH] Crop a clear person in reportage instead of saying nobody was found. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A single figure with empty floor — someone walking, a suitcase beside them — is the subject. The crop keeps the body and what they carry. A conversation, a distant figure, and a frame that is already full stay as shot. --- apps/api/src/composition/compose.ts | 81 +++++++++++++++------- apps/api/src/composition/detect.ts | 5 +- apps/api/src/composition/planFrame.test.ts | 32 +++++++-- apps/api/src/composition/routes.ts | 12 +++- apps/api/src/composition/yolox.ts | 9 ++- apps/api/test/compose.test.ts | 46 +++++++----- apps/app/src/i18n.ts | 1 + apps/app/src/offline/detectLocal.ts | 5 +- apps/app/src/pages/DevelopPage.tsx | 11 ++- docs/photo-editing-rules.md | 12 ++-- 10 files changed, 150 insertions(+), 64 deletions(-) diff --git a/apps/api/src/composition/compose.ts b/apps/api/src/composition/compose.ts index aef40aa..98a460d 100644 --- a/apps/api/src/composition/compose.ts +++ b/apps/api/src/composition/compose.ts @@ -14,12 +14,12 @@ * stays whole when that person stays in the crop. A crop that slices a ball is not a crop. * - An open frame with a team in it stays open: the row is the subject, and the crop does not drop people out of it. * - Cutting another sharp person in half is avoided; cutting blurred ones doesn't matter. - * - A generic event is reportage. The crop reads the shot the way a picture editor does, and trusts the - * framing: a long shot is the place, a full-length or a group whose bodies are whole stays as it was made, - * and a frame the camera already closed is only finished (mid-limb, a person already cut off at the edge - * left out). It is not zoomed to a sports fill. The space left around someone was left on purpose. - * A prime of 100mm or longer may step one notch closer on a single full-length, because it cannot zoom. - * A long shot and a group stay. That step stays centred on the photograph. + * - A generic event is reportage. One clear person is the subject, even with empty floor around them + * (someone walking, a suitcase beside them): the crop keeps the whole body and what they carry, and + * cuts that empty floor. It is not a sports fill. A conversation stays as framed. A distant figure + * (under about a fifth of the frame) is the place. A figure that already fills the frame stays. + * A frame the camera already closed is only finished (mid-limb). A person already cut off at the edge + * is left 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. * @@ -60,6 +60,8 @@ export interface Detections { height: number; people: Detection[]; balls: Detection[]; + /** Suitcase, handbag or backpack next to a person. Part of the subject, not scenery. */ + carried?: Detection[]; } export interface Composition { @@ -344,19 +346,45 @@ function edgeAccident(p: Detection, tallest: number): boolean { } /** - * Reportage: the frame is the photograph. True when closing it would throw away a plan the camera finished. - * A person already cut off at the edge of a full-length is the exception: they are not the picture. + * A person shorter than this is scenery in a place, not who the photo is about. + * Taller than this, alone in the frame, they are the subject — a suitcase and empty floor do not hide them. */ -function framedOnPurpose(inSubject: Detection[], others: Detection[]): boolean { +const CLEAR_PERSON = 0.22; + +/** + * Reportage leaves the photograph when it is not one clear person with room around them. + * A conversation stays. A distant figure stays. A body that already fills the height stays. + * Someone the frame already cut off at the edge is not a reason to leave the rest. + */ +function leaveAsShot(inSubject: Detection[], others: Detection[]): boolean { const intent = shotIntent(inSubject); - if (!intent) return false; - if (intent === "closed") return false; - if (intent === "scene") return true; - const tallest = Math.max(...inSubject.map(h)); - for (const p of others) { - if (edgeAccident(p, tallest)) return false; + if (!intent || intent === "closed") return false; + const tallestPerson = inSubject.reduce((a, b) => (h(b) > h(a) ? b : a)); + const tallest = h(tallestPerson); + if (others.some((p) => edgeAccident(p, tallest))) return false; + if (intent === "group") return true; + // Several people under half the frame: the place, or a wide shot. One person that size is the subject. + if (intent === "scene" && inSubject.length > 1) return true; + if (tallest < CLEAR_PERSON) return true; + if (tallestPerson.y0 <= 0.06 && tallestPerson.y1 >= 0.94) return true; + return false; +} + +/** A bag or suitcase touching the person is part of the subject. One across the frame is not. */ +function withCarried(box: Box, people: Detection[], carried: readonly Detection[] | undefined): Box { + if (!carried?.length) return box; + let out = box; + for (const item of carried) { + if (item.score < 0.35) continue; + let close = false; + for (const p of people) { + const gapX = Math.max(0, Math.max(p.x0, item.x0) - Math.min(p.x1, item.x1)); + const gapY = Math.max(0, Math.max(p.y0, item.y0) - Math.min(p.y1, item.y1)); + if (overlap(p, item) > 0 || (gapX < 0.12 && gapY < 0.15)) close = true; + } + if (close) out = union(out, item); } - return true; + return out; } /** @@ -562,14 +590,15 @@ export function compose(d: Detections, aspect: number | null = null, opts: Compo const detected = reportage ? forReportage(d, faces) : d; const found = findSubject(detected, opts.focus, { reportage, sport: opts.sport ?? null, faces }); if (!found) return null; - const { box: s, reason, people: inSubject, ball } = found; + const { reason, people: inSubject, ball } = found; + const s = withCarried(found.box, inSubject, d.carried); const ratio = (aspect ?? d.width / d.height) * (d.height / d.width); // width/height in frame fractions const tallest = Math.max(...inSubject.map(h)); const others = detected.people.filter((p) => p.score >= MIN_PERSON && !inSubject.includes(p)); - // A long shot, a full-length, or a group the camera already finished. The margins are the picture. - // A long prime is the exception on one full-length: the lens could not zoom, so one step closer is allowed. + // A conversation, a distant figure, or a body that already fills the frame stays as shot. + // One clear person does not: empty floor and a suitcase are not "no subject". const primeFigure = reportage && isLongPrime(opts.lens) && shotIntent(inSubject) === "figure"; - if (reportage && framedOnPurpose(inSubject, others) && !primeFigure) return null; + if (reportage && leaveAsShot(inSubject, others)) return null; // Zoom at the wide end: the photographer opened on purpose — do not reframe (level only later). if (isWideZoomOpen(opts.lens)) return null; const headroom = 0.04 * tallest; @@ -620,9 +649,10 @@ export function compose(d: Detections, aspect: number | null = null, opts: Compo if (cut) return finish(cut); } // Whole bodies, feet included. A little headroom gives way before a complete foot does. - const whole = frame(s, ratio, sole, headroom, tallest, others, inSubject, reason, minWidth, false, false, reportage, balls, primeFigure, lead, edgeClutter) - ?? frame(s, ratio, sole, 0, tallest, others, inSubject, reason, minWidth, false, false, reportage, balls, primeFigure, lead, edgeClutter) - ?? frame(s, ratio, s.y1, 0, tallest, others, inSubject, reason, minWidth, false, false, reportage, balls, primeFigure, lead, edgeClutter); + // One person: score a real crop (empty floor goes). Do not prefer the untouched frame. + const whole = frame(s, ratio, sole, headroom, tallest, others, inSubject, reason, minWidth, false, false, reportage, balls, primeFigure, lead, edgeClutter, false) + ?? frame(s, ratio, sole, 0, tallest, others, inSubject, reason, minWidth, false, false, reportage, balls, primeFigure, lead, edgeClutter, false) + ?? frame(s, ratio, s.y1, 0, tallest, others, inSubject, reason, minWidth, false, false, reportage, balls, primeFigure, lead, edgeClutter, false); if (whole || feetIn) return finish(whole); return finish(frame(s, ratio, s.y0 + MID_THIGH * tallest, headroom, tallest, others, inSubject, reason, minWidth, false, true, reportage, balls, false, lead, edgeClutter)); } @@ -662,7 +692,7 @@ export function minCropWidth(width: number, height: number, minLongEdge = 2400): return Math.min(1, Math.max(floor, 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, pinBottom = false, reportage = false, balls: readonly Box[] = [], closer = false, lead: -1 | 0 | 1 = 0, edgeClutter?: (rect: Box) => number): (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, reportage = false, balls: readonly Box[] = [], closer = false, lead: -1 | 0 | 1 = 0, edgeClutter?: (rect: Box) => number, holdFrame?: boolean): (Composition & { cost: number }) | null { const mainSharp = Math.max(...inSubject.map(sharp)); const keep = requiredBox(s, inSubject); let best: { rect: Box; cost: number } | null = null; @@ -705,7 +735,8 @@ function frame(s: Box, ratio: number, mustBottom: number, headroom: number, tall // A player the photographer left in the picture stays in it. Cutting them out, or through the body, // is not a crop. Soft scenery may still go. if (dropsPlayer(r, others, mainSharp, tallest)) continue; - const c = cost(r, s, others, ch, tallest, mainSharp, ratio, inSubject, tight, reportage, closer, lead, edgeClutter, minWidth) + jointCost(r, inSubject, others, mainSharp); + const stayWide = holdFrame ?? reportage; + const c = cost(r, s, others, ch, tallest, mainSharp, ratio, inSubject, tight, stayWide, closer, lead, edgeClutter, minWidth) + jointCost(r, inSubject, others, mainSharp); if (!best || c < best.cost) best = { rect: r, cost: c }; } } diff --git a/apps/api/src/composition/detect.ts b/apps/api/src/composition/detect.ts index f75ebdf..b029c33 100644 --- a/apps/api/src/composition/detect.ts +++ b/apps/api/src/composition/detect.ts @@ -4,7 +4,7 @@ import * as ort from "onnxruntime-node"; import { modelsDir } from "../lib/models.js"; import sharp from "sharp"; import type { Detection, Detections } from "./compose.js"; -import { BALL, PERSON, YOLOX_SIZE, decodeYolox, nmsKeep, sharpnessOf } from "./yolox.js"; +import { BACKPACK, BALL, HANDBAG, PERSON, SUITCASE, YOLOX_SIZE, decodeYolox, nmsKeep, sharpnessOf } from "./yolox.js"; /** * People and balls in a photo, with YOLOX-s (Apache-2.0, COCO classes; infra/faces/download-models.sh fetches it). @@ -94,7 +94,8 @@ export class SubjectDetector { const all = decodeYolox(raw, scale, width, height); const people = nmsKeep(all.filter((d) => d.cls === PERSON)); await addSharpness(file, people); - return { width, height, people, balls: nmsKeep(all.filter((d) => d.cls === BALL)) }; + const carried = nmsKeep(all.filter((d) => d.cls === BACKPACK || d.cls === HANDBAG || d.cls === SUITCASE)); + return { width, height, people, balls: nmsKeep(all.filter((d) => d.cls === BALL)), carried }; } } diff --git a/apps/api/src/composition/planFrame.test.ts b/apps/api/src/composition/planFrame.test.ts index fb1f813..8b1e7e3 100644 --- a/apps/api/src/composition/planFrame.test.ts +++ b/apps/api/src/composition/planFrame.test.ts @@ -55,12 +55,13 @@ describe("planFrame", () => { expect(crop.params.aspect).toEqual([6000, 4000]); }); - it("does not close a reportage frame the camera left open, even when matches are cropped tight", () => { + it("crops one clear person in reportage and ignores a learnt sports cut", () => { + const person = { x0: 0.35, y0: 0.28, x1: 0.52, y1: 0.72 }; const planned = planFrame({ detections: { width: 6000, height: 4000, - people: [{ x0: 0.35, y0: 0.28, x1: 0.52, y1: 0.72, score: 0.9, sharpness: 1 }], + people: [{ ...person, score: 0.9, sharpness: 1 }], balls: [], }, width: 6000, @@ -71,7 +72,17 @@ describe("planFrame", () => { cropBias: { dx: 0, dy: 0, scale: 0.8, dAngle: 0, cut: 0.5, head: 0.02, sides: 0.1 }, settings, }); - expect(planned.ops.some((op) => op.command === "crop.set")).toBe(false); + const crop = planned.ops.find((op) => op.command === "crop.set"); + expect(crop?.command).toBe("crop.set"); + if (!crop || crop.command !== "crop.set") return; + const rect = crop.params.rect; + expect(rect.x0).toBeLessThanOrEqual(person.x0); + expect(rect.x1).toBeGreaterThanOrEqual(person.x1); + expect(rect.y0).toBeLessThanOrEqual(person.y0); + expect(rect.y1).toBeGreaterThan(person.y1); + expect(rect.x1 - rect.x0).toBeLessThan(0.92); + // The learnt match cut (half the body) must not land on this photograph. + expect(rect.y1).toBeGreaterThan(person.y0 + 0.7 * (person.y1 - person.y0)); }); it("does not apply a learnt cut that chops a player the crop had kept", () => { @@ -98,12 +109,13 @@ describe("planFrame", () => { expect(crop.params.rect.x1).toBeGreaterThanOrEqual(0.62); }); - it("does not close a reportage full-length the camera already composed", () => { + it("crops a reportage full-length that still has empty floor around the person", () => { + const person = { x0: 0.3, y0: 0.12, x1: 0.48, y1: 0.82 }; const planned = planFrame({ detections: { width: 6000, height: 4000, - people: [{ x0: 0.3, y0: 0.12, x1: 0.48, y1: 0.82, score: 0.9, sharpness: 1 }], + people: [{ ...person, score: 0.9, sharpness: 1 }], balls: [], }, width: 6000, @@ -113,7 +125,15 @@ describe("planFrame", () => { angle: 0, settings, }); - expect(planned.ops.some((op) => op.command === "crop.set")).toBe(false); + const crop = planned.ops.find((op) => op.command === "crop.set"); + expect(crop?.command).toBe("crop.set"); + if (!crop || crop.command !== "crop.set") return; + const rect = crop.params.rect; + expect(rect.y0).toBeLessThanOrEqual(person.y0); + expect(rect.y1).toBeGreaterThan(person.y1); + expect(rect.x0).toBeLessThanOrEqual(person.x0); + expect(rect.x1).toBeGreaterThanOrEqual(person.x1); + expect(rect.x1 - rect.x0).toBeLessThan(0.92); }); it("reduces the straighten angle when leveling would chop the subject's feet", () => { diff --git a/apps/api/src/composition/routes.ts b/apps/api/src/composition/routes.ts index 1bfce1c..1f404d9 100644 --- a/apps/api/src/composition/routes.ts +++ b/apps/api/src/composition/routes.ts @@ -11,7 +11,7 @@ import { modelsDir } from "../lib/models.js"; import type { LocalStorage } from "../storage/storage.js"; import { readFocusPoint } from "../ingest/exif.js"; import { focusFromExifJson } from "../ingest/focus.js"; -import { compose, isReportage } from "./compose.js"; +import { compose, findSubject, isReportage } from "./compose.js"; import { lazyDetector } from "./detect.js"; const Params = z.object({ photoId: z.uuid() }); @@ -51,7 +51,15 @@ export async function registerCompositionRoutes(app: FastifyInstance, deps: { db const original = photo.originalStored ? storage.resolve(photo.storageKey) : preview; const focus = focusFromExifJson(photo.exif) ?? (existsSync(original) ? await readFocusPoint(original) : null); const context = isReportage(photo.event) ? "reportage" : "sport"; - return { crop: compose(detections, aspect ? aspect[0] / aspect[1] : null, { focus, context, faces: photo.faces, sport: photo.event?.sport ?? null }) }; + const faces = photo.faces; + const sport = photo.event?.sport ?? null; + const crop = compose(detections, aspect ? aspect[0] / aspect[1] : null, { focus, context, faces, sport }); + let found = crop != null; + if (!found) { + const subject = findSubject(detections, focus, { reportage: context === "reportage", sport, faces }); + found = subject != null; + } + return { crop, found }; }); /** YOLOX-s, so the desktop can crop with the same detector. Not a face model: no biometrics gate. */ diff --git a/apps/api/src/composition/yolox.ts b/apps/api/src/composition/yolox.ts index a673e1e..6ebd4ce 100644 --- a/apps/api/src/composition/yolox.ts +++ b/apps/api/src/composition/yolox.ts @@ -1,10 +1,15 @@ import type { Detection } from "./compose.js"; -/** YOLOX-s input. People are COCO class 0, the sports ball is class 32. */ +/** YOLOX-s input. People are COCO class 0, the sports ball is class 32. Bags travel with the person. */ export const YOLOX_SIZE = 640; export const PERSON = 0; +export const BACKPACK = 24; +export const HANDBAG = 26; +export const SUITCASE = 28; export const BALL = 32; +const WANTED = [PERSON, BALL, BACKPACK, HANDBAG, SUITCASE]; + export interface RawDet extends Detection { cls: number; } @@ -23,7 +28,7 @@ export function decodeYolox(raw: Float32Array, scale: number, width: number, hei const o = a * stride; const obj = raw[o + 4]!; if (obj < 0.1) continue; - for (const cls of [PERSON, BALL]) { + for (const cls of WANTED) { const score = obj * raw[o + 5 + cls]!; if (score < 0.25) continue; const bx = (raw[o]! + x) * s; diff --git a/apps/api/test/compose.test.ts b/apps/api/test/compose.test.ts index 64b2235..21a9e42 100644 --- a/apps/api/test/compose.test.ts +++ b/apps/api/test/compose.test.ts @@ -198,10 +198,12 @@ describe("reportage", () => { expect(shotIntent([person(0.36, 0.15, 0.66, 0.996)])).toBe("closed"); }); - it("leaves a wide frame as shot", () => { + it("crops a single person standing in the frame, and keeps them whole", () => { const speaker = person(0.35, 0.28, 0.52, 0.72); - const room = compose({ ...frame, people: [speaker], balls: [] }, null, { context: "reportage" }); - expect(room).toBeNull(); + const room = compose({ ...frame, people: [speaker], balls: [] }, null, { context: "reportage" })!; + expect(inside(room.rect, speaker)).toBe(true); + expect(room.rect.x1 - room.rect.x0).toBeLessThan(0.92); + expect(room.rect.y1).toBeGreaterThan(speaker.y1); const match = compose({ ...frame, people: [speaker], balls: [] }, null, { context: "sport" }); expect(match).not.toBeNull(); }); @@ -216,7 +218,7 @@ describe("reportage", () => { expect(isLongPrime({ focalLength: 200 })).toBe(false); }); - it("steps a full-length closer on a long prime, and leaves the same frame on a zoom", () => { + it("crops a full-length on a prime and on a zoom, and keeps a suitcase with the person", () => { const p = person(0.3, 0.12, 0.48, 0.82); const photo = { ...frame, people: [p], balls: [] }; const prime = compose(photo, null, { context: "reportage", lens: { focalLength: 135, range: [135, 135] } })!; @@ -225,19 +227,24 @@ describe("reportage", () => { expect(prime.rect.x0).toBeLessThanOrEqual(p.x0); expect(prime.rect.x1).toBeGreaterThanOrEqual(p.x1); const width = prime.rect.x1 - prime.rect.x0; - expect(width).toBeGreaterThan(0.8); + expect(width).toBeGreaterThan(0.7); expect(width).toBeLessThan(0.92); - const zoom = compose(photo, null, { context: "reportage", lens: { focalLength: 135, range: [70, 200] } }); - expect(zoom).toBeNull(); + const zoom = compose(photo, null, { context: "reportage", lens: { focalLength: 135, range: [70, 200] } })!; + expect(inside(zoom.rect, p)).toBe(true); + expect(zoom.rect.x1 - zoom.rect.x0).toBeLessThan(0.92); const wide = person(0.35, 0.28, 0.52, 0.72); - const scene = compose({ ...frame, people: [wide], balls: [] }, null, { context: "reportage", lens: { focalLength: 200, range: [200, 200] } }); - expect(scene).toBeNull(); + const suitcase = { x0: 0.54, y0: 0.5, x1: 0.64, y1: 0.7, score: 0.8 }; + const scene = compose({ ...frame, people: [wide], balls: [], carried: [suitcase] }, null, { context: "reportage", lens: { focalLength: 200, range: [200, 200] } })!; + expect(inside(scene.rect, wide)).toBe(true); + expect(inside(scene.rect, suitcase)).toBe(true); + expect(scene.rect.y1).toBeGreaterThan(suitcase.y1); }); - it("leaves a full-length as it was framed, and a match of the same picture still closes", () => { + it("crops a reportage full-length without a sports fill, and a match of the same picture still closes", () => { const p = person(0.3, 0.12, 0.48, 0.82); - const room = compose({ ...frame, people: [p], balls: [] }, null, { framing: "tight", context: "reportage" }); - expect(room).toBeNull(); + const room = compose({ ...frame, people: [p], balls: [] }, null, { framing: "tight", context: "reportage" })!; + expect(inside(room.rect, p)).toBe(true); + expect(room.rect.x1 - room.rect.x0).toBeLessThan(0.92); const match = compose({ ...frame, people: [p], balls: [] }, null, { framing: "tight", context: "sport" }); expect(match).not.toBeNull(); if (!match) return; @@ -294,8 +301,10 @@ describe("reportage", () => { it("does not close a full-length to delete a hand at the edge", () => { 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" }); - expect(c).toBeNull(); + const c = compose({ ...frame, people: [subject, hand], balls: [] }, null, { context: "reportage" })!; + expect(inside(c.rect, subject)).toBe(true); + 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.5); }); it("drops a person the frame already cut off, and keeps the full-length around the subject", () => { @@ -308,7 +317,7 @@ describe("reportage", () => { expect(c.rect.x1).toBeGreaterThanOrEqual(subject.x1); expect(c.rect.y0).toBeLessThanOrEqual(subject.y0); expect(c.rect.y1).toBeGreaterThan(subject.y1); - expect(c.rect.y1 - c.rect.y0).toBeGreaterThan(0.8); + expect(c.rect.y1 - c.rect.y0).toBeGreaterThan(0.7); }); it("crops the whole person at the car, not the sharper face in the window", () => { @@ -347,8 +356,11 @@ describe("reportage", () => { { x0: 0.5, y0: 0.25, x1: 0.56, y1: 0.34 }, { x0: 0.4, y0: 0.31, x1: 0.45, y1: 0.4 }, ], - }); - expect(c).toBeNull(); + })!; + expect(c.rect.y0).toBeLessThanOrEqual(front.y0); + expect(c.rect.y1).toBeGreaterThan(front.y1 - 1e-6); + expect(c.rect.x0).toBeLessThanOrEqual(front.x0); + expect(c.rect.x1).toBeGreaterThanOrEqual(front.x1); }); it("leaves a wide shot of small figures as it was framed", () => { diff --git a/apps/app/src/i18n.ts b/apps/app/src/i18n.ts index 4c353a9..21190ad 100644 --- a/apps/app/src/i18n.ts +++ b/apps/app/src/i18n.ts @@ -1337,6 +1337,7 @@ export const t = { level: "Nivelar", autoCropHelp: "Recorte automático à volta de quem a foto é: a bola e quem a disputa, ou o grupo principal, sem cortar corpos a meio.", autoCropNone: "Não encontrei um assunto claro nesta foto para recortar.", + autoCropKept: "A foto já está enquadrada à volta de quem está nela.", autoCropMissing: "O recorte automático ainda não está instalado neste servidor.", levelHelp: "Endireita a foto pelo horizonte ou pelas linhas verticais.", levelNone: "Não encontrei horizonte nem linhas verticais claras nesta foto: endireita com o ângulo.", diff --git a/apps/app/src/offline/detectLocal.ts b/apps/app/src/offline/detectLocal.ts index 053341c..58d1e11 100644 --- a/apps/app/src/offline/detectLocal.ts +++ b/apps/app/src/offline/detectLocal.ts @@ -1,5 +1,5 @@ import type { Detections } from "../../../api/src/composition/compose.js"; -import { YOLOX_SIZE, decodeYolox, nmsKeep, sharpnessOf, PERSON, BALL } from "../../../api/src/composition/yolox.js"; +import { BACKPACK, BALL, HANDBAG, PERSON, SUITCASE, YOLOX_SIZE, decodeYolox, nmsKeep, sharpnessOf } from "../../../api/src/composition/yolox.js"; import type { ApiClient } from "@photoreport/sdk"; import { kv } from "./kv.js"; @@ -96,7 +96,8 @@ export async function detectPreview(api: ApiClient, orgId: string, jpeg: ArrayBu const grey = new Uint8Array(greyW * greyH); for (let i = 0; i < grey.length; i++) grey[i] = Math.round(0.299 * rgba[i * 4]! + 0.587 * rgba[i * 4 + 1]! + 0.114 * rgba[i * 4 + 2]!); sharpnessOf(grey, greyW, greyH, people); - return { width, height, people, balls: nmsKeep(all.filter((d) => d.cls === BALL)) }; + const carried = nmsKeep(all.filter((d) => d.cls === BACKPACK || d.cls === HANDBAG || d.cls === SUITCASE)); + return { width, height, people, balls: nmsKeep(all.filter((d) => d.cls === BALL)), carried }; } catch { return null; } finally { diff --git a/apps/app/src/pages/DevelopPage.tsx b/apps/app/src/pages/DevelopPage.tsx index c462072..35e63d3 100644 --- a/apps/app/src/pages/DevelopPage.tsx +++ b/apps/app/src/pages/DevelopPage.tsx @@ -577,8 +577,15 @@ export function DevelopPage() { const c0 = cropOf(session.settings); const aspect: [number, number] | null = c0.aspect ?? (choice === "original" || choice === null ? null : choice); try { - const { crop } = await api.request<{ crop: { rect: Crop["rect"]; reason: string } | null }>("POST", `/v1/photos/${current.id}/auto-crop`, { aspect }); - if (!crop) return setNote(t.dev.autoCropNone); + const answer = await api.request<{ + crop: { rect: Crop["rect"]; reason: string } | null; + found?: boolean; + }>("POST", `/v1/photos/${current.id}/auto-crop`, { aspect }); + if (!answer.crop) { + if (answer.found) return setNote(t.dev.autoCropKept); + return setNote(t.dev.autoCropNone); + } + const crop = answer.crop; const c = cropOf(session.settings); const rect = constrainRotated(crop.rect, c.angle, sourceSize.w, sourceSize.h); session.edit({ command: "crop.set", params: { rect, angle: c.angle, aspect: c.aspect ?? (aspect ?? [sourceSize.w, sourceSize.h]) } }); diff --git a/docs/photo-editing-rules.md b/docs/photo-editing-rules.md index 3116d25..087b6a3 100644 --- a/docs/photo-editing-rules.md +++ b/docs/photo-editing-rules.md @@ -58,12 +58,12 @@ Following the AP and NPPA codes: 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. -- **Reportage** reads the shot the way a picture editor does, and trusts the framing. A long shot (the person - under half the picture) is the place. A full-length, or a conversation whose bodies are whole, is already the - photograph: the space around them was left on purpose, and it is not closed to match a sports fill. A prime of - 100mm or longer is the exception on a single full-length: that lens cannot zoom, so the crop may step in to - about 85% of the frame, still centred on the photograph. A zoom (even at 200mm) is not that exception — the - photographer could have zoomed, so the space stays. A long shot and a group stay on a prime too. A frame the +- **Reportage** reads the shot the way a picture editor does. One clear person is the subject — someone + walking in the middle, a suitcase or a bag beside them — even when they take less than half the frame. + The crop keeps the whole body and what they carry, cuts empty floor and edge clutter, and keeps the + photograph's aspect. It does not say there is no subject. It is not a sports fill. A conversation (several + people whose bodies are whole) stays as framed. A distant figure, under about a fifth of the frame, is the + place and stays. A figure that already fills the height stays. A zoom at its wide end stays. A frame the camera already cut (the feet leave the picture, and the person is large) is only finished, at mid-limb, and a person the frame already cut off at the edge is left out. The sports framing on the event is ignored, including a crop learnt from matches. A later frame of that moment may still be a half or a three-quarter. A whole hand -- 2.47.3