fix: bind tag projection to each frame origin
This commit is contained in:
parent
05cf32e1d9
commit
d5a7a56dff
4 changed files with 146 additions and 35 deletions
|
|
@ -307,6 +307,80 @@ class TagPassIntegrationTests(unittest.TestCase):
|
|||
)
|
||||
engine.shutdown()
|
||||
|
||||
def test_overlapping_frames_keep_their_own_origin(self):
|
||||
"""A later worker must not become the previous-frame baseline or steal origin."""
|
||||
session, engine, _ = self.make_tagged_session()
|
||||
|
||||
class Ordered:
|
||||
def __init__(self):
|
||||
self.inside = 0
|
||||
self.max_inside = 0
|
||||
self.calls = 0
|
||||
self._inner = threading.Lock()
|
||||
|
||||
def register(self, image):
|
||||
with self._inner:
|
||||
self.inside += 1
|
||||
self.max_inside = max(self.max_inside, self.inside)
|
||||
self.calls += 1
|
||||
call = self.calls
|
||||
time.sleep(0.03)
|
||||
with self._inner:
|
||||
self.inside -= 1
|
||||
return (0.0, -400.0)
|
||||
|
||||
session._shift_map = Ordered()
|
||||
errors = []
|
||||
|
||||
def run(frame_id):
|
||||
try:
|
||||
session.process_frame(frame_id, frame_bytes())
|
||||
except Exception as exc:
|
||||
errors.append(exc)
|
||||
|
||||
early = threading.Thread(target=run, args=(1,))
|
||||
late = threading.Thread(target=run, args=(2,))
|
||||
early.start()
|
||||
late.start()
|
||||
early.join(2.0)
|
||||
late.join(2.0)
|
||||
self.assertEqual(errors, [])
|
||||
self.assertFalse(early.is_alive() or late.is_alive())
|
||||
self.assertEqual(session._shift_map.calls, 2)
|
||||
self.assertEqual(session._shift_map.max_inside, 1)
|
||||
self.assertEqual(session._frame_origin[1], 800.0)
|
||||
engine.shutdown()
|
||||
|
||||
def test_cached_tag_projects_at_this_frame_origin(self):
|
||||
"""A panned frame must not attach a tag that only overlaps the previous origin."""
|
||||
from tags import TagRecord
|
||||
|
||||
session, engine, _ = self.make_tagged_session()
|
||||
record = TagRecord(
|
||||
tag_id="cached", box=[150, 700, 190, 760], band_index=0, name="cached", price=150,
|
||||
flags=["tax_consistent"],
|
||||
)
|
||||
record.settled = True
|
||||
session._tags._tags[record.tag_id] = record
|
||||
|
||||
class Panned:
|
||||
def __init__(self):
|
||||
self.calls = 0
|
||||
|
||||
def register(self, image):
|
||||
self.calls += 1
|
||||
return (0.0, -400.0) if self.calls == 2 else (0.0, 0.0)
|
||||
|
||||
session._shift_map = Panned()
|
||||
first = session.process_frame(1, frame_bytes())
|
||||
self.assertFalse(any(track.get("price_tag", {}).get("id") for track in first["tracks"]))
|
||||
second = session.process_frame(2, frame_bytes())
|
||||
bound = [track["price_tag"] for track in second["tracks"] if track.get("price_tag", {}).get("id")]
|
||||
self.assertTrue(bound)
|
||||
self.assertGreaterEqual(bound[0]["box"][1], 200)
|
||||
self.assertLess(bound[0]["box"][1], 480)
|
||||
engine.shutdown()
|
||||
|
||||
|
||||
class FramePipelineTests(unittest.TestCase):
|
||||
def test_latest_frame_wins_and_drops_are_counted(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue