Fix duplicate parameter declaration in the face detector node

recognition_model was declared twice (once for the existence check, once for the
recognizer), so the node raised ParameterAlreadyDeclared at start-up and never
published. Declare each parameter once, and add a test that constructs the node,
since nothing else exercised it.

Recognition then works live: with the owner enrolled, 29 of 31 detections over
14 s were named, at detector scores around 0.9.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFN8nRRCiDiMN7ChBpHJhs
This commit is contained in:
2026-10-04 23:33:21 -07:00
co-authored by Claude Sonnet 5.5
parent ac4e09bf35
commit 79920ff6bc
2 changed files with 20 additions and 3 deletions
@@ -31,11 +31,13 @@ class FaceDetectorNode(Node):
self.debug = bool(param('publish_debug', False))
self.detector = FaceDetector(param('model_path', ''), float(param('score_threshold', 0.6)),
int(param('min_size', 40)))
recognition_model = os.path.expanduser(param('recognition_model', DEFAULT_MODEL)) # declare once
faces_db = param('faces_db', DEFAULT_DB)
threshold = float(param('recognition_threshold', COSINE_THRESHOLD))
self.recognizer = None
if bool(param('recognize', True)) and self.detector.backend == 'yunet' \
and os.path.exists(os.path.expanduser(param('recognition_model', DEFAULT_MODEL))):
self.recognizer = FaceRecognizer(param('recognition_model', DEFAULT_MODEL), param('faces_db', DEFAULT_DB),
float(param('recognition_threshold', COSINE_THRESHOLD)))
and os.path.exists(recognition_model):
self.recognizer = FaceRecognizer(recognition_model, faces_db, threshold)
self.pub = self.create_publisher(Detection2DArray, '/vision/faces', 10)
self.debug_pub = (self.create_publisher(CompressedImage, '/vision/faces/debug/compressed', 1)
if self.debug else None)
+15
View File
@@ -0,0 +1,15 @@
import pytest
rclpy = pytest.importorskip('rclpy')
def test_the_node_constructs_with_default_parameters():
"""Declaring a parameter twice raises at construction, and nothing else exercises the node."""
from hermes_vision.face_detector_node import FaceDetectorNode
rclpy.init()
try:
node = FaceDetectorNode()
assert node.detector.backend in ('yunet', 'haar')
node.destroy_node()
finally:
rclpy.shutdown()