mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-13 04:25:32 +08:00
- 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
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from dataclasses import dataclass, field
|
|
|
|
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
|
|
]
|