Improve held object and colour recognition; add posture answers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -142,6 +142,52 @@ assert seeing._clothes_answer(p, "what colour are my shoes?", "en") == "Your sho
|
||||
assert seeing._clothes_answer(p, "신발 뭐 신었어?", "ko") == "신발은 흰색으로 보여요."
|
||||
assert seeing._clothes_answer(p, "내가 뭐 입고 있어?", "ko") == "빨간색 상의에 검은색 바지를 입고, 흰색 신발을 신고 계세요."
|
||||
|
||||
# ---------- a held cup's colour under a warm lamp: the box's middle, the light taken out (2026-10-23 live: a yellow cup
|
||||
# read "white", then "yellow"); fingers over the box bottom; the old whole-box reading said orange / red ----------
|
||||
WARM = np.array((0.68, 0.86, 1.0)) # B, G, R of the lamp
|
||||
for want, true in (("yellow", (40, 210, 240)), ("white", (235, 235, 235)), ("blue", (200, 90, 30))):
|
||||
for light in (WARM, np.ones(3)):
|
||||
img = (np.full((720, 1280, 3), 250.0) * light).astype(np.uint8) # a white wall
|
||||
img[560:640, 850:900] = (np.array(true) * light).astype(np.uint8)
|
||||
img[630:660, 840:910] = (np.array((110, 140, 200)) * light).astype(np.uint8) # the fingers
|
||||
depth = np.full((720, 1280), 2500, np.uint16)
|
||||
depth[100:700, 500:900] = 1000
|
||||
frame = {"camera": "torso", "color": img, "depth": depth, "people": [], "head_yaw": 0.0, "intr": intr,
|
||||
"T": np.eye(4), "objects": [{"name": "cup", "score": 0.8, "box": (845, 555, 905, 660)}]}
|
||||
got = scene._held(frame, k, "left", 600)["object"]["colour"]
|
||||
assert got == want, (want, light, got)
|
||||
for name in ("holding_cup_back", "white_shirt_near"): # a neutral room: no change
|
||||
assert all(abs(g - 1) < 0.08 for f in fx(name) for g in scene._gains(f["color"])), name
|
||||
|
||||
# ---------- something in a hand the detector has no class for: not skin, at the hand's depth ----------
|
||||
img = np.full((720, 1280, 3), 200, np.uint8)
|
||||
depth = np.full((720, 1280), 2500, np.uint16)
|
||||
depth[100:700, 500:900] = 1000
|
||||
frame = {"camera": "torso", "color": img, "depth": depth, "people": [], "head_yaw": 0.0, "intr": intr, "T": np.eye(4),
|
||||
"objects": []}
|
||||
img[560:640, 845:905] = (40, 160, 40) # a green thing past the wrist
|
||||
h = scene._held(frame, k, "left", 600)
|
||||
assert h["object"] is None and h["something"]["colour"] == "green", h
|
||||
depth[575:700, 830:920] = 1250 # the body 25 cm behind: empty
|
||||
assert scene._held(frame, k, "left", 600)["something"] == {"colour": None, "share": 0.0}
|
||||
|
||||
# ---------- sitting / standing / crouching from keypoints (torso 300 px) ----------
|
||||
legs = {"standing": dict(left_knee=(680, 860), right_knee=(600, 860), left_ankle=(680, 1100), right_ankle=(600, 1100)),
|
||||
"sitting": dict(left_knee=(690, 640), right_knee=(590, 640), left_ankle=(690, 900), right_ankle=(590, 900)),
|
||||
"crouching": dict(left_knee=(720, 610), right_knee=(560, 610), left_ankle=(690, 800), right_ankle=(590, 800))}
|
||||
for want, kn in legs.items():
|
||||
assert scene._posture(kp(**body, **kn)) == want, want
|
||||
assert scene._posture(kp(**body)) is None # no knees in view
|
||||
for said, posture, lang, want in (("Am I sitting or standing?", "sitting", "en", "You're sitting."),
|
||||
("I am standing or sitting.", "standing", "en", "You're standing."), # 2026-10-23
|
||||
("am I standing?", "sitting", "en", "No, you're sitting."),
|
||||
("am I sitting?", "sitting", "en", "Yes, you're sitting."),
|
||||
("내가 앉아 있어 서 있어?", "crouching", "ko", "쪼그려 앉아 계세요."),
|
||||
("나 서 있어?", "standing", "ko", "네, 서 계세요."),
|
||||
("Am I sitting or standing?", None, "en", "I can't see your legs")):
|
||||
assert next(k for k, rx in seeing.KINDS if rx.search(said)) == "posture", said
|
||||
assert seeing._posture_answer({"posture": posture}, said, lang).startswith(want), (said, want)
|
||||
|
||||
# ---------- words that are not about the cameras ----------
|
||||
f = fx("empty_room")
|
||||
for text in ("how far is Seoul?", "what time is it?", "is there a cafe nearby?", "what are you doing?",
|
||||
|
||||
@@ -59,9 +59,14 @@ def _person(p):
|
||||
if p is None:
|
||||
return None
|
||||
seen = p.get("hands_visible", True)
|
||||
hands = {s: ({"position_mm": None, "object": _thing(*p[f"{s}_hand"]) if isinstance(p.get(f"{s}_hand"), (list, tuple))
|
||||
hands = {s: ({"position_mm": None, "distance_m": 0.8, "object": _thing(*p[f"{s}_hand"]) if isinstance(p.get(f"{s}_hand"), (list, tuple))
|
||||
else (_thing(p[f"{s}_hand"], None) if p.get(f"{s}_hand") else None)} if seen else None)
|
||||
for s in ("left", "right")}
|
||||
for s, h in hands.items(): # the palm check: something without a class shows as a colour
|
||||
raw = p.get(f"{s}_hand")
|
||||
if h is not None:
|
||||
h["something"] = None if h["object"] else {"colour": (raw[1] if isinstance(raw, (list, tuple)) else None) or
|
||||
"grey", "share": 0.5} if raw else {"colour": None, "share": 0.0}
|
||||
return {"distance_m": p.get("dist_m"), "bearing_deg": BEARING.get(p.get("side"), 0.0), "where": _where(p.get("side")),
|
||||
"position_mm": None, "camera": "head", "facing": True, "gesture": None,
|
||||
"raised": [p["raised"]] if p.get("raised") else [], "pointing": None, "hands": hands,
|
||||
@@ -111,6 +116,22 @@ scene.pointing_target = lambda frames=None: None
|
||||
scene.ask_vlm = lambda q, lang="en", frames=None: None
|
||||
|
||||
|
||||
def ask_vlm_hand(evidence, lang="en", frames=None, side=None):
|
||||
"""The close look names a thing the detector has no class for (a watch), as gemma4 does on the hand picture."""
|
||||
p = _front(frames)
|
||||
for s in ((side,) if side else ("right", "left")):
|
||||
raw = p and p.get(f"{s}_hand")
|
||||
name = raw and (raw[0] if isinstance(raw, (list, tuple)) else raw)
|
||||
if name and not _thing(name, None):
|
||||
k = {"watch": "시계"}.get(name, name)
|
||||
return f"You're holding a {name} in your {s} hand." if lang == "en" else \
|
||||
f"{seeing.KO_SIDE[s]}손에 {seeing._j(k, '을', '를')} 들고 계세요."
|
||||
return None
|
||||
|
||||
|
||||
scene.ask_vlm_hand = ask_vlm_hand
|
||||
|
||||
|
||||
def lang_of(text):
|
||||
return "ko" if re.search(r"[가-힣]", text) else "en"
|
||||
|
||||
@@ -118,7 +139,7 @@ def lang_of(text):
|
||||
def run(dialogues):
|
||||
ok, bad, asked = 0, [], 0
|
||||
for n, d in enumerate(dialogues):
|
||||
seeing._last.update(thing=None, name=None, kind=None, asked=None, parts=[], at=0.0)
|
||||
seeing._last.update(thing=None, name=None, kind=None, asked=None, parts=[], held=None, unsure=0.0, at=0.0)
|
||||
b = brain.Brain()
|
||||
marks = d.get("markers") or MARKS
|
||||
for i, turn in enumerate(d["turns"]):
|
||||
|
||||
@@ -35,7 +35,7 @@ def person_in_front(frames=None):
|
||||
w = _now(frames)
|
||||
if not w.get("person", True):
|
||||
return None
|
||||
hands = {s: {"position_mm": None, "object": None} for s in ("left", "right")}
|
||||
hands = {s: {"position_mm": None, "distance_m": 0.8, "object": None} for s in ("left", "right")}
|
||||
if w.get("hand"):
|
||||
hands[w["hand"]]["object"] = {"name": w["thing"], "colour": w["colour"], "position_mm": None,
|
||||
"distance_m": 0.8, "width_mm": None}
|
||||
@@ -59,6 +59,7 @@ scene.object_in_hand = object_in_hand
|
||||
scene.person_holds = lambda obj=None, frames=None: bool(_now(frames).get("hand"))
|
||||
scene.people = lambda frames=None: [{}] if _now(frames).get("person", True) else []
|
||||
scene.ask_vlm = lambda q, lang="en", frames=None: "VLM"
|
||||
scene.ask_vlm_hand = lambda evidence, lang="en", frames=None, side=None: None
|
||||
scene.things = lambda frames=None: []
|
||||
|
||||
|
||||
@@ -75,7 +76,7 @@ def say(text):
|
||||
|
||||
def dialogue(turns):
|
||||
"""turns: (words, world change before them or None, regex the answer must match; "llm": not a seeing answer)."""
|
||||
seeing._last.update(thing=None, name=None, kind=None, asked=None, parts=[], at=0.0)
|
||||
seeing._last.update(thing=None, name=None, kind=None, asked=None, parts=[], held=None, unsure=0.0, at=0.0)
|
||||
for words, change, want in turns:
|
||||
if change:
|
||||
world.update(change)
|
||||
@@ -151,7 +152,7 @@ dialogue([("What is my hand?", None, r"black laptop in your right hand"),
|
||||
("and the other hand?", None, r"^In your right hand I see a black laptop"),
|
||||
("and this one?", None, LEFT_UP),
|
||||
("really?", None, r"looked again.*left hand is up"),
|
||||
("What about Inna's left hand?", {"raised": []}, r"^I don't see anything I can recognise in your left hand"),
|
||||
("What about Inna's left hand?", {"raised": []}, r"^I don't see anything in your left hand"),
|
||||
("What's in my right hand?", None, r"^In your right hand I see a black laptop"),
|
||||
("No, it's my left hand.", None, r"laptop in your right hand, but I may be wrong")]) # a claim stays a claim
|
||||
world.update(raised=["left"])
|
||||
@@ -167,8 +168,8 @@ world.update(raised=[])
|
||||
# nothing in the hand any more, or nobody there
|
||||
world.update(START)
|
||||
dialogue([("what am I holding?", None, r"left hand"),
|
||||
("and now?", {"hand": None}, r"don't see anything I can recognise in your hands"),
|
||||
("it's in my right hand", None, r"don't see anything I can recognise in your hands"),
|
||||
("and now?", {"hand": None}, r"don't see anything in your hands"),
|
||||
("it's in my right hand", None, r"don't see anything in your hands"),
|
||||
("what about now?", {"person": False}, r"can't see you")])
|
||||
|
||||
# no follow-up without a seeing answer just before; an order is never a correction
|
||||
@@ -234,4 +235,64 @@ assert lumi.Lumi.own_echo("The school is over.", share=lumi.ECHO_LIKELY_SHARE)
|
||||
assert not lumi.Lumi.own_echo("What about Busan?", share=lumi.ECHO_LIKELY_SHARE)
|
||||
assert not lumi.Lumi.own_echo("Look it up.", share=lumi.ECHO_LIKELY_SHARE)
|
||||
|
||||
# "what am I holding" tries hard before giving up: fresh looks until two agree, the colour steady across questions,
|
||||
# then the close look (gemma4 on the hand picture), then a request for a hint and a new look after it (2026-10-23 live:
|
||||
# a phone found only sometimes, a laptop "I can't tell" 4-5 times, a yellow cup "white" then "yellow")
|
||||
def person(right=None, something=None):
|
||||
"""A person in front whose right hand holds `right` ((name, colour, score) or None)."""
|
||||
obj = right and {"name": right[0], "colour": right[1], "score": right[2], "position_mm": None, "distance_m": 0.8,
|
||||
"width_mm": None}
|
||||
hand = {"position_mm": None, "distance_m": 0.8, "object": obj, "something": something or {"colour": None, "share": 0}}
|
||||
return {"hands": {"right": hand, "left": {**hand, "object": None, "something": {"colour": None, "share": 0}}},
|
||||
"raised": [], "posture": None}
|
||||
|
||||
|
||||
def held(views, said="what am I holding?", vlm=None, hint=None):
|
||||
"""The answer when the first look sees views[0] and each new look (more()) the next; also the close look's words
|
||||
and what Lumi said before it."""
|
||||
views, spoken, asked_vlm = list(views), [], []
|
||||
scene.person_in_front = lambda frames: frames[0]["p"]
|
||||
scene.ask_vlm_hand = lambda evidence, lang="en", frames=None, side=None: asked_vlm.append(evidence) or vlm
|
||||
more = lambda: [{"p": views.pop(0)}] if views else None
|
||||
got = seeing._held_answer([{"p": views.pop(0)}], "en", None, more, spoken.append, hint)
|
||||
return got, spoken, asked_vlm
|
||||
|
||||
|
||||
seeing._last.update(held=None, unsure=0.0)
|
||||
PHONE = ("cell phone", "black", 0.22) # a weak box: true only when two looks agree
|
||||
got, spoken, _ = held([person(PHONE), person(PHONE)])
|
||||
assert got == "You're holding a black cell phone in your right hand." and not spoken, got
|
||||
got, spoken, ev = held([person(PHONE), person(), person()], vlm="UNSURE")
|
||||
assert spoken == ["Let me look closely."] and "cell phone (score 0.22" in ev[0], (spoken, ev)
|
||||
assert got == "It might be a black cell phone in your right hand, but I'm not sure. Could you turn it toward me, or " \
|
||||
"tell me what it is?", got
|
||||
got, _, _ = held([person(), person(), person()], hint="phone", vlm=None)
|
||||
assert got == "I still can't make it out well, so I'll take your word: it's a phone.", got
|
||||
got, _, _ = held([person(("cell phone", "black", 0.5))], hint="phone")
|
||||
assert got.startswith("Yes, now I see it: a black cell phone"), got
|
||||
LAPTOP = ("laptop", "grey", 0.6)
|
||||
got, spoken, _ = held([person(), person(), person(LAPTOP)]) # found on the third look: no close look
|
||||
assert got == "You're holding a grey laptop in your right hand." and not spoken, got
|
||||
got, spoken, ev = held([person(something={"colour": "green", "share": 0.6})] * 3, vlm="You're holding a green ball.")
|
||||
assert got == "You're holding a green ball." and "something green" in ev[0], (got, ev)
|
||||
got, _, _ = held([person(something={"colour": "green", "share": 0.6})] * 3, vlm=None)
|
||||
assert got.startswith("I see something green in your right hand, but I can't tell what it is. Could you turn"), got
|
||||
got, spoken, _ = held([person()] * 3) # depth at the hands, nothing there
|
||||
assert got == "I don't see anything in your hands." and not spoken, got
|
||||
|
||||
seeing._last.update(held=None) # the colour stays steady ...
|
||||
assert held([person(("cup", "yellow", 0.8))])[0].endswith("a yellow cup in your right hand.")
|
||||
assert held([person(("cup", "white", 0.8)), person(("cup", "yellow", 0.8))])[0].endswith("a yellow cup in your right hand.")
|
||||
assert held([person(("cup", "white", 0.8)), person(("cup", "orange", 0.8)), person(("cup", "yellow", 0.8))])[0] \
|
||||
.endswith("a yellow cup in your right hand.")
|
||||
assert held([person(("cup", "white", 0.8)), person(("cup", "white", 0.8))])[0].endswith("a white cup in your right hand.")
|
||||
seeing._last["held"]["at"] -= seeing.STEADY_S + 1 # ... for STEADY_S, then a new look decides
|
||||
assert held([person(("cup", "yellow", 0.8))])[0].endswith("a yellow cup in your right hand.")
|
||||
# the model is told the same colour
|
||||
assert seeing._steady({"name": "cup", "colour": "white"})["colour"] == "yellow"
|
||||
|
||||
for said, want in (("it's my wallet", "wallet"), ("이거 지갑이야", "지갑"), ("no, it's a phone", "phone"),
|
||||
("it's my right hand", None), ("okay", None), ("제가 서 있나요 앉아 있나요?", None)):
|
||||
assert seeing._hint(said) == want, (said, seeing._hint(said))
|
||||
|
||||
print("seeing fresh ok")
|
||||
|
||||
Reference in New Issue
Block a user