4#include <opencv2/opencv.hpp>
5#include <cv_bridge/cv_bridge.hpp>
36 void initialize(
const rclcpp::Node::SharedPtr& node)
override
39 node->declare_parameter(
"driver.vision.OpenCVDriver.name",
"OpenCVDriver");
40 node->declare_parameter(
"driver.vision.OpenCVDriver.device_id", 0);
43 name_ = node->get_parameter(
"driver.vision.OpenCVDriver.name").as_string();
44 device_id = node->get_parameter(
"driver.vision.OpenCVDriver.device_id").as_int();
50 RCLCPP_INFO(
node_->get_logger(),
"Assigned driver name: %s",
name_.c_str());
51 RCLCPP_INFO(
node_->get_logger(),
"Assigned driver device_id: %d",
device_id);
53 RCLCPP_INFO(
node_->get_logger(),
"OpenCVDriver starting on video device %d",
device_id);
61 RCLCPP_ERROR(
node_->get_logger(),
"OpenCVDriver failed to open video device ID: %d",
device_id);
68 [
this](diagnostic_updater::DiagnosticStatusWrapper& status) {
produce_diagnostics(status); });
71 RCLCPP_INFO(
node_->get_logger(),
"OpenCVDriver started on video device %d",
device_id);
84 RCLCPP_INFO(
node_->get_logger(),
"OpenCVDriver stopped.");
113 vision.
image = frame;
125 RCLCPP_INFO(
node_->get_logger(),
"OpenCVDriver test function called");
131 cv::imwrite(
"test/opencv_vision_image.jpg",
captureFrame().image);
133 RCLCPP_INFO(
node_->get_logger(),
"OpenCVDriver test image saved to 'test/opencv_vision_image.jpg'. Test "
141 status.summary(diagnostic_msgs::msg::DiagnosticStatus::ERROR,
"Camera device is not open");
143 status.summary(diagnostic_msgs::msg::DiagnosticStatus::WARN,
"Camera capture has recent failures");
145 status.summary(diagnostic_msgs::msg::DiagnosticStatus::OK,
"Camera capture healthy");
148 status.add(
"device_open",
capture_device.isOpened() ?
"true" :
"false");
void check_directory(std::string folder_name)
Check if the test directory exists, create it if not.
Definition driver_base.hpp:68
std::mutex buffer_mutex_
Mutex to protect access to the driver data.
Definition driver_base.hpp:149
std::string name_
Name of the driver.
Definition driver_base.hpp:143
rclcpp::Node::SharedPtr node_
ROS node for the driver.
Definition driver_base.hpp:138
void initialize_base(const rclcpp::Node::SharedPtr &node)
Initializer base driver in place of constructor due to plugin semantics.
Definition driver_base.hpp:95
void disable_diagnostics()
Definition driver_base.hpp:129
bool diagnostics_enabled() const
Definition driver_base.hpp:105
void enable_diagnostics(const std::string &hardware_id, const std::string &task_name, std::function< void(diagnostic_updater::DiagnosticStatusWrapper &)> task, std::chrono::milliseconds period=std::chrono::seconds(1))
Definition driver_base.hpp:110
OpenCVDriver class for handling video input from a camera using OpenCV.
Definition opencv_vision_driver.hpp:19
std::atomic< uint64_t > capture_failure_count_
Definition opencv_vision_driver.hpp:156
std::atomic< uint64_t > successful_capture_count_
Definition opencv_vision_driver.hpp:155
void initialize(const rclcpp::Node::SharedPtr &node) override
Initialize the driver.
Definition opencv_vision_driver.hpp:36
cv::VideoCapture capture_device
Definition opencv_vision_driver.hpp:154
~OpenCVDriver() override
Definition opencv_vision_driver.hpp:24
int device_id
Definition opencv_vision_driver.hpp:153
void test() override
Test function to check the driver functionality by writing the image to a file This function creates ...
Definition opencv_vision_driver.hpp:123
void deinitialize() override
Stop driver streaming.
Definition opencv_vision_driver.hpp:78
void produce_diagnostics(diagnostic_updater::DiagnosticStatusWrapper &status)
Definition opencv_vision_driver.hpp:138
OpenCVDriver()
Definition opencv_vision_driver.hpp:21
vision_frame captureFrame() override
Get the latest image data from the driver.
Definition opencv_vision_driver.hpp:94
Definition vision_source_driver.hpp:10
Definition audio_buffer.hpp:16
Base class for driver exceptions.
Definition exceptions.hpp:14
Definition structs.hpp:12
cv::Mat image
Definition structs.hpp:13
rclcpp::Time stamp
Definition structs.hpp:15
std::string frame_id
Definition structs.hpp:14