screengraft 0.38.0 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/detect.py +59 -28
- package/skills/inject-screenshot/SKILL.md +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screengraft",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "Put a UI screenshot or screen recording onto a photographed device screen with the perspective exactly right \u2014 a homography you confirm by hand, not a generative guess.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mockup",
|
package/scripts/detect.py
CHANGED
|
@@ -996,22 +996,63 @@ def arbitrate(results, shape, click=None):
|
|
|
996
996
|
sat = next((r for r in results if r["method"] == "saturation"), None)
|
|
997
997
|
why = "it was the only detector left after the rounded-corner filter" \
|
|
998
998
|
if len(results) == 1 else "its tone band assumption held, which is itself evidence"
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
999
|
+
# ONE region-vs-edge arbitration, for whichever region channel survived the
|
|
1000
|
+
# rounded-corner filter above. Until 11 Sep 2026 only tone got the nesting
|
|
1001
|
+
# rules; saturation-vs-edge fell through to "saturation wins". On iPhone-4
|
|
1002
|
+
# that returned a saturation quad 18% off, nested around an edge quad 3%
|
|
1003
|
+
# off at 94% of its area -- exactly the "screen inside a body" shape the
|
|
1004
|
+
# tone branch already knew how to read.
|
|
1005
|
+
region = t if t is not None else sat
|
|
1006
|
+
rname = "tone" if t is not None else "saturation"
|
|
1007
|
+
if region is not None and e is not None:
|
|
1008
|
+
rq, eq = region["_corners_np"], e["_corners_np"]
|
|
1009
|
+
ra = float(cv2.contourArea(rq.astype(np.float32)))
|
|
1002
1010
|
ea = float(cv2.contourArea(eq.astype(np.float32)))
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1011
|
+
# Nesting is read on whichever quad is inside the other. It used to be
|
|
1012
|
+
# read only with the region quad inside the edge quad, so an edge quad
|
|
1013
|
+
# sitting inside a region quad (iPhone-4: edge 3% off inside a
|
|
1014
|
+
# saturation quad 18% off at 94%) was "not nested" and fell through to
|
|
1015
|
+
# the region winning by default.
|
|
1016
|
+
inner, outer = (region, e) if ra < ea else (e, region)
|
|
1017
|
+
iname, oname = (rname, "edge") if ra < ea else ("edge", rname)
|
|
1018
|
+
nested = overlap_frac(inner["_corners_np"], outer["_corners_np"]) >= 0.90
|
|
1019
|
+
ratio = min(ra, ea) / max(ra, ea) if max(ra, ea) > 0 else 0.0
|
|
1020
|
+
ti, to = shape_tier(inner), shape_tier(outer)
|
|
1021
|
+
tr, te = shape_tier(region), shape_tier(e)
|
|
1022
|
+
# Nested: shape evidence first, the area ratio only to break a tie.
|
|
1023
|
+
#
|
|
1024
|
+
# The ratio alone reads "small inside big" as content-inside-screen and
|
|
1025
|
+
# "large inside big" as screen-inside-body, and it is right on the
|
|
1026
|
+
# gradient-screen fixture (41%: a slab on the screen) and on most
|
|
1027
|
+
# photographs. It is wrong exactly when the quads' own corners say the
|
|
1028
|
+
# opposite: a UI content region at 96% of the screen with loose corners
|
|
1029
|
+
# (two of ten labelled photographs, 15% off) is not a screen inside a
|
|
1030
|
+
# body, and a confident phone screen at 34% of a loosely-rounded table
|
|
1031
|
+
# (the hand-built case in test_detect) is not content on it. Tiers
|
|
1032
|
+
# decide those; at equal tiers the ratio still does, unchanged.
|
|
1033
|
+
if nested and to > ti:
|
|
1034
|
+
best, why = outer, ("the %s quad sits inside the %s quad at %.0f%% of its "
|
|
1035
|
+
"area, but the outer quad's corners agree on a radius "
|
|
1036
|
+
"(tier %d) and the inner's do not (tier %d) — content "
|
|
1037
|
+
"inside a screen, not a screen inside a body"
|
|
1038
|
+
% (iname, oname, ratio * 100, to, ti))
|
|
1039
|
+
elif nested and ti > to:
|
|
1040
|
+
best, why = inner, ("the %s quad sits inside the %s quad at %.0f%% of its "
|
|
1041
|
+
"area, and the inner quad's corners agree on a radius "
|
|
1042
|
+
"(tier %d) where the outer's do not (tier %d) — a "
|
|
1043
|
+
"screen on something larger"
|
|
1044
|
+
% (iname, oname, ratio * 100, ti, to))
|
|
1045
|
+
elif nested and ratio < NEST_FLOOR:
|
|
1046
|
+
best, why = outer, ("the %s quad is only %.0f%% of the %s quad it sits "
|
|
1047
|
+
"inside — that's content drawn on the screen, not the "
|
|
1048
|
+
"screen" % (iname, ratio * 100, oname))
|
|
1009
1049
|
elif nested:
|
|
1010
|
-
best, why =
|
|
1011
|
-
|
|
1012
|
-
|
|
1050
|
+
best, why = inner, ("the %s quad sits inside the %s quad at %.0f%% of "
|
|
1051
|
+
"its area — a screen inside a device body"
|
|
1052
|
+
% (iname, oname, ratio * 100))
|
|
1053
|
+
elif te > tr:
|
|
1013
1054
|
# Not nested, and the edge quad's own shape says "screen" more
|
|
1014
|
-
# strongly than
|
|
1055
|
+
# strongly than the region's does. Before 11 Sep 2026 tone won here
|
|
1015
1056
|
# unconditionally, on the argument that its band assumption holding
|
|
1016
1057
|
# was itself evidence -- and on two of ten labelled photographs that
|
|
1017
1058
|
# handed the answer to a tone quad 159% and 249% off, with corner
|
|
@@ -1019,22 +1060,12 @@ def arbitrate(results, shape, click=None):
|
|
|
1019
1060
|
# radius. A band assumption is weaker evidence than four agreeing
|
|
1020
1061
|
# corners; the tiers say so and this reads them.
|
|
1021
1062
|
best, why = e, ("the two quads aren't nested and the edge quad's "
|
|
1022
|
-
"corners agree on a radius (tier %d) where
|
|
1023
|
-
"not (tier %d)" % (
|
|
1063
|
+
"corners agree on a radius (tier %d) where %s's do "
|
|
1064
|
+
"not (tier %d)" % (te, rname, tr))
|
|
1024
1065
|
else:
|
|
1025
|
-
best, why =
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
# tone was dropped for having sharp corners, or never fired. The
|
|
1029
|
-
# surviving region detector measured a real corner radius; edge usually
|
|
1030
|
-
# cannot -- but when it did, and more confidently, it wins the same way.
|
|
1031
|
-
if e is not None and shape_tier(e) > shape_tier(sat):
|
|
1032
|
-
best, why = e, ("the edge quad's corners agree on a radius (tier %d) "
|
|
1033
|
-
"where saturation's do not (tier %d)"
|
|
1034
|
-
% (shape_tier(e), shape_tier(sat)))
|
|
1035
|
-
else:
|
|
1036
|
-
best, why = sat, ("the saturation detector found a region with rounded "
|
|
1037
|
-
"corners where tone did not")
|
|
1066
|
+
best, why = region, ("the two quads aren't nested; %s's assumption "
|
|
1067
|
+
"holding is itself evidence that it found a screen"
|
|
1068
|
+
% rname)
|
|
1038
1069
|
else:
|
|
1039
1070
|
best = t or e or sat
|
|
1040
1071
|
if best is None:
|
|
@@ -5,7 +5,7 @@ description: Injects a UI screenshot OR a screen recording onto a photographed d
|
|
|
5
5
|
|
|
6
6
|
# Inject a screenshot onto a photographed device
|
|
7
7
|
|
|
8
|
-
**What ships (v0.
|
|
8
|
+
**What ships (v0.39):** a local browser UI (`scripts/ui.py`) that walks the designer through the whole job — pick the photo and the screen source, which may be an image **or a video** (recent Desktop/Downloads images, drag-drop, browse, path, or a **Figma frame link**), auto-detect the screen as a starting position — and when detection cannot tell which region is a screen, **Point at screen**: one click inside it and the detector uses that point — or, if this photograph has been fitted before, **the fit it was saved with comes back** as the starting position instead of a detection, recognised by the photo's own pixels so a rename or a drag-drop still match — and every save also writes a **portable `.fit.json` beside the mockup** that can be dropped back onto the page later, which is how a fit survives a re-export, another machine, or someone else's hands — then **match the four edges** (drag an edge's middle to slide it, near an end to pivot; corners still draggable) with canvas navigation that follows the usual conventions — **hold ⌘ and scroll to zoom to the pointer, hold space and drag to pan** — and a rectified strip loupe. The fit and the composite sit **side by side and always have** — the result pane re-renders as you drag, which is how a corner gets judged, so it is the layout rather than a mode you can switch off. Then an on-by-default realism pass that colour-matches the source to the photo's light, **Save** (or **Render**, for a video) into the project folder (`--out-dir`), and a **Send to Claude** button that reaches you through the plugin's own MCP server. The UI is a hand port of the project's Figma design file — dark only.
|
|
9
9
|
|
|
10
10
|
The geometry is exact (`warp.py`); the detection is advisory (`detect.py`) and the human corrects it. **When a detection is wrong and you want to know why**, ask for the candidate list: `POST /api/detect {"trace": true}` writes `<session>/candidates.json`, or run `python3 scripts/detect.py --photo P --out-corners /tmp/c.json --trace /tmp/t.json` (add `--click X,Y`). Every candidate quad is in there with its score and whether it was accepted, rejected, never reached, or filtered out by the click — which is what separates "the screen was never proposed" from "it was proposed and something else won".
|
|
11
11
|
|