diff --git a/ros/hermes_vision/hermes_vision/face_detector_node.py b/ros/hermes_vision/hermes_vision/face_detector_node.py index 18b03b2..a643b91 100644 --- a/ros/hermes_vision/hermes_vision/face_detector_node.py +++ b/ros/hermes_vision/hermes_vision/face_detector_node.py @@ -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) diff --git a/ros/hermes_vision/test/test_node.py b/ros/hermes_vision/test/test_node.py new file mode 100644 index 0000000..e220114 --- /dev/null +++ b/ros/hermes_vision/test/test_node.py @@ -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()