1+ #ifndef COMMON_INTERFACES_CPP__CAMERA_HPP_
2+ #define COMMON_INTERFACES_CPP__CAMERA_HPP_
3+
4+ #include < string>
5+ #include < memory>
6+ #include " rclcpp/rclcpp.hpp"
7+ #include " sensor_msgs/msg/image.hpp"
8+ #include < opencv2/opencv.hpp>
9+ #include < cv_bridge/cv_bridge.h>
10+
11+ /* ### AUXILIARY FUNCTIONS ### */
12+
13+ const int MAXRANGE = 8 ; // max length received from imageD
14+ const int MINRANGE = 0 ;
15+
16+ /* Represents a camera image with metadata and pixel data. */
17+ class Image {
18+ public:
19+ Image ();
20+ int height; // Image height [pixels]
21+ int width; // Image width [pixels]
22+ double timeStamp; // Time stamp [s] */
23+ std::string format; // Image format string (RGB8, BGR,...)
24+ cv::Mat data; // The image data itself
25+
26+ std::string to_string () const ;
27+ };
28+
29+ // Declaración de función auxiliar implícita en tu código Python
30+ cv::Mat depthToRGB8 (const cv::Mat& gray_img_buff, const std::string& encoding);
31+
32+ /*
33+ * Convert a ROS Image message to a JdeRobot Image object.
34+ *
35+ * Args:
36+ * img: ROS sensor_msgs/Image message.
37+ *
38+ * Returns:
39+ * Image object with BGR data, or None if the message is empty.
40+ */
41+ std::shared_ptr<Image> imageMsg2Image (const sensor_msgs::msg::Image& img);
42+
43+ /* ### HAL INTERFACE ### */
44+
45+ /* ROS2 node that subscribes to a camera topic and stores the latest image. */
46+ class CameraNode : public rclcpp ::Node {
47+ public:
48+ CameraNode (const std::string& topic);
49+
50+ /*
51+ * Return the latest camera image.
52+ *
53+ * Returns:
54+ * Image object with BGR data, or None if no image has been received.
55+ */
56+ std::shared_ptr<Image> getImage () const ;
57+
58+ private:
59+ /* Store the latest image message received from the topic. */
60+ void listener_callback (const sensor_msgs::msg::Image::SharedPtr msg);
61+
62+ rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr sub_;
63+ sensor_msgs::msg::Image last_img_;
64+ };
65+
66+ #endif
0 commit comments