mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-12 20:15:31 +08:00
feat(scenegraph): add SoftwareCamIndex for visual hash similarity queries
- Add SoftwareCamIndex class with xnor_popcount_score for CAM-style matching - Add CamMatch and SceneGraphMatch dataclasses for query results - Add query_by_visual_hash method to SimpleSceneGraph - Add comprehensive tests for SoftwareCamIndex and xnor_popcount_score
This commit is contained in:
@@ -1,10 +1,42 @@
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from .roomnode import RoomNode
|
||||
from .objectnode import ObjectNode
|
||||
from .roomnode import RoomNode
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SceneGraphMatch:
|
||||
obj_id: str
|
||||
node: ObjectNode
|
||||
row_index: int
|
||||
score: int
|
||||
similarity: float
|
||||
hash_bytes: bytes
|
||||
|
||||
|
||||
@dataclass
|
||||
class SimpleSceneGraph:
|
||||
rooms: dict[str, RoomNode] = field(default_factory=dict)
|
||||
objects: dict[str, ObjectNode] = field(default_factory=dict)
|
||||
|
||||
def query_by_visual_hash(
|
||||
self,
|
||||
query_hash_bytes: bytes,
|
||||
*,
|
||||
top_k: int = 1,
|
||||
) -> list[SceneGraphMatch]:
|
||||
from .software_cam import SoftwareCamIndex
|
||||
|
||||
index = SoftwareCamIndex.from_scene_graph(self)
|
||||
cam_matches = index.query(query_hash_bytes, top_k=top_k)
|
||||
return [
|
||||
SceneGraphMatch(
|
||||
obj_id=match.obj_id,
|
||||
node=self.objects[match.obj_id],
|
||||
row_index=match.row_index,
|
||||
score=match.score,
|
||||
similarity=match.similarity,
|
||||
hash_bytes=match.hash_bytes,
|
||||
)
|
||||
for match in cam_matches
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user