Fix autopilot.test.ts: full-size photos so crops clear the delivery floor (BIT-33293) #306
No files matched your search
@@ -55,6 +55,21 @@ describe("planFrame", () => {
|
||||
expect(crop.params.aspect).toEqual([6000, 4000]);
|
||||
});
|
||||
|
||||
it("scores no composition for a frame too small to crop above the delivery floor, and does for a full-size one", () => {
|
||||
const frame = (width: number, height: number) =>
|
||||
planFrame({
|
||||
detections: { width, height, people: [{ x0: 0.42, y0: 0.2, x1: 0.58, y1: 0.85, score: 0.9, sharpness: 1, focus: 300 }], balls: [] },
|
||||
width,
|
||||
height,
|
||||
reportage: false,
|
||||
values: null,
|
||||
angle: 0,
|
||||
settings: { ...settings, minLongEdge: 2400 },
|
||||
});
|
||||
expect(frame(600, 400).composition).toBeNull();
|
||||
expect(frame(6000, 4000).composition).not.toBeNull();
|
||||
});
|
||||
|
||||
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({
|
||||
|
||||
@@ -25,7 +25,7 @@ class FakeEngine implements RenderEngine {
|
||||
}
|
||||
async render(job: RenderJob) {
|
||||
await copyFile(job.input, job.output);
|
||||
return { width: 600, height: 400 };
|
||||
return { width: PHOTO_W, height: PHOTO_H };
|
||||
}
|
||||
async auto() {
|
||||
return { values: { "wb.temp": 5200, "wb.tint": 4, "light.exposure": 0.4, "light.contrast": 20 }, angle: 1.5 };
|
||||
@@ -33,13 +33,20 @@ class FakeEngine implements RenderEngine {
|
||||
async close() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Photos are full-size on purpose: the planner refuses any crop near the delivery floor (minLongEdge 2400 px),
|
||||
* so on a 600 px stand-in every frame had no composition, scored 0 and the picks became arbitrary.
|
||||
*/
|
||||
const PHOTO_W = 6000;
|
||||
const PHOTO_H = 4000;
|
||||
|
||||
/** A player in the middle; `focus` per photo (keyed by the sha in the preview's file name). */
|
||||
class FakeDetector {
|
||||
readonly focus = new Map<string, number>();
|
||||
async detect(file: string): Promise<Detections> {
|
||||
const sha = path.basename(file).split(".")[0]!;
|
||||
const focus = this.focus.get(sha) ?? 100;
|
||||
return { width: 600, height: 400, people: [{ x0: 0.42, y0: 0.2, x1: 0.58, y1: 0.85, score: 0.9, sharpness: 1, focus }], balls: [] };
|
||||
return { width: PHOTO_W, height: PHOTO_H, people: [{ x0: 0.42, y0: 0.2, x1: 0.58, y1: 0.85, score: 0.9, sharpness: 1, focus }], balls: [] };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +259,7 @@ describe("autopilot", () => {
|
||||
let n = 0;
|
||||
async function shot(orgId: string, userId: string, eventId: string, at: number, focus: number, source: "FTP" | "UPLOAD" | "CLOUD" = "FTP") {
|
||||
n++;
|
||||
const data = await sharp({ create: { width: 600, height: 400, channels: 3, background: { r: (n * 31) % 256, g: 90, b: 120 } } }).jpeg().toBuffer();
|
||||
const data = await sharp({ create: { width: PHOTO_W, height: PHOTO_H, channels: 3, background: { r: (n * 31) % 256, g: 90, b: 120 } } }).jpeg().toBuffer();
|
||||
const { createHash } = await import("node:crypto");
|
||||
detector.focus.set(createHash("sha256").update(data).digest("hex"), focus);
|
||||
const file = path.join(dir, `IMG_${n}.JPG`);
|
||||
@@ -454,7 +461,7 @@ describe("autopilot", () => {
|
||||
const shrink = (a: number, b: number) => [a + (b - a) * 0.08, b - (b - a) * 0.08] as const;
|
||||
const [x0, x1] = shrink(r.x0, r.x1);
|
||||
const [y0, y1] = shrink(r.y0, r.y1);
|
||||
await develop.append(id, userId, { clientId: "web-1", ops: [{ opId: `h-${id}-1`, command: { command: "develop.set", params: { values: { "light.exposure": 0.5 } } } }, { opId: `h-${id}-2`, command: { command: "crop.set", params: { rect: { x0, y0, x1, y1 }, angle: 1.5, aspect: [600, 400] } } }] });
|
||||
await develop.append(id, userId, { clientId: "web-1", ops: [{ opId: `h-${id}-1`, command: { command: "develop.set", params: { values: { "light.exposure": 0.5 } } } }, { opId: `h-${id}-2`, command: { command: "crop.set", params: { rect: { x0, y0, x1, y1 }, angle: 1.5, aspect: [PHOTO_W, PHOTO_H] } } }] });
|
||||
expect(await recordCorrection(ctx.db, id)).toBe(true);
|
||||
}
|
||||
// Untouched photos and the autopilot's own edits teach nothing.
|
||||
|
||||
Reference in new issue
Block a user