Keep a complete foot when the head is already at the top #53
No files matched your search
@@ -217,7 +217,10 @@ export function compose(d: Detections, aspect: number | null = null, opts: Compo
|
||||
// Feet that are whole in the photo stay in. Mid-shin and mid-thigh are only for a body the frame does
|
||||
// not finish, and only when the whole body cannot fit. The hip (a joint) is never the cut.
|
||||
if (feetIn) {
|
||||
const whole = frame(s, ratio, sole, headroom, tallest, others, inSubject, reason, minWidth, true);
|
||||
// Headroom gives way before a complete foot does. Cutting the leg is not how a tight frame is made.
|
||||
const whole = frame(s, ratio, sole, headroom, tallest, others, inSubject, reason, minWidth, true)
|
||||
?? frame(s, ratio, sole, 0, tallest, others, inSubject, reason, minWidth, true)
|
||||
?? frame(s, ratio, s.y1, 0, tallest, others, inSubject, reason, minWidth, true);
|
||||
if (whole) return { rect: whole.rect, subject: whole.subject, reason: whole.reason, people: whole.people };
|
||||
}
|
||||
const tries = [keep(s.y0 + MID_SHIN * tallest), keep(s.y0 + MID_THIGH * tallest)]
|
||||
@@ -227,10 +230,13 @@ export function compose(d: Detections, aspect: number | null = null, opts: Compo
|
||||
if (best) return { rect: best.rect, subject: best.subject, reason: best.reason, people: best.people };
|
||||
return frame(s, ratio, keep(s.y0 + MID_THIGH * tallest), headroom, tallest, others, inSubject, reason, minWidth, true);
|
||||
}
|
||||
// Whole bodies, feet included; only when that can't fit, mid-thigh (between hip and knee), never the foot.
|
||||
return frame(s, ratio, sole, headroom, tallest, others, inSubject, reason, minWidth)
|
||||
?? frame(s, ratio, s.y1, headroom, tallest, others, inSubject, reason, minWidth)
|
||||
?? frame(s, ratio, s.y0 + MID_THIGH * tallest, headroom, tallest, others, inSubject, reason, minWidth);
|
||||
// Whole bodies, feet included. A little headroom gives way before a complete foot does. Mid-thigh only when
|
||||
// the foot already leaves the photo, or the whole body cannot fit at all.
|
||||
const whole = frame(s, ratio, sole, headroom, tallest, others, inSubject, reason, minWidth)
|
||||
?? frame(s, ratio, sole, 0, tallest, others, inSubject, reason, minWidth)
|
||||
?? frame(s, ratio, s.y1, 0, tallest, others, inSubject, reason, minWidth);
|
||||
if (whole || feetIn) return whole;
|
||||
return frame(s, ratio, s.y0 + MID_THIGH * tallest, headroom, tallest, others, inSubject, reason, minWidth);
|
||||
}
|
||||
|
||||
/** Recommended narrowest crop for a photo `width` px wide when deliveries need `minLongEdge` px (and never below a third). */
|
||||
|
||||
@@ -144,6 +144,13 @@ describe("reportage", () => {
|
||||
expect((p.y1 - p.y0) / (c.rect.y1 - c.rect.y0)).toBeLessThan(1);
|
||||
});
|
||||
|
||||
it("keeps a complete foot when the head is already against the top edge", () => {
|
||||
const p = person(0.4, 0.02, 0.55, 0.984);
|
||||
const c = compose({ ...frame, people: [p], balls: [] }, null, { framing: "tight", context: "reportage" })!;
|
||||
expect(c.rect.y1).toBeGreaterThan(p.y1 - 1e-6);
|
||||
expect(c.rect.y0).toBeLessThanOrEqual(p.y0 + 1e-6);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user