Skip to content

Commit

Permalink
fix: image msg assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
borednuna committed Jan 23, 2024
1 parent 76135aa commit f1e07fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(keisan REQUIRED)
find_package(ninshiki_interfaces REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(OpenCV REQUIRED)
Expand All @@ -41,6 +42,7 @@ ament_target_dependencies(${PROJECT_NAME}
keisan
ninshiki_interfaces
OpenCV
cv_bridge
rclcpp
std_msgs
sensor_msgs
Expand Down Expand Up @@ -75,6 +77,7 @@ ament_export_dependencies(
ninshiki_interfaces
OpenCV
rclcpp
cv_bridge
std_msgs
sensor_msgs
shisen_cpp
Expand Down
5 changes: 4 additions & 1 deletion include/ninshiki_cpp/node/ninshiki_cpp_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "shisen_interfaces/msg/image.hpp"
#include "shisen_cpp/shisen_cpp.hpp"
#include "sensor_msgs/msg/image.hpp"
#include <cv_bridge/cv_bridge.h>

namespace ninshiki_cpp::node
{
Expand Down Expand Up @@ -74,7 +75,9 @@ class NinshikiCppNode
std::shared_ptr<ColorDetector> color_detection;
std::shared_ptr<LBPDetector> lbp_detection;
std::shared_ptr<shisen_cpp::camera::ImageProvider> image_provider;
std::shared_ptr<sensor_msgs::msg::Image> image_msg;

sensor_msgs::msg::Image::SharedPtr image_msg;
cv_bridge::CvImage cv_image;

cv::Mat received_frame;
cv::Mat hsv_frame;
Expand Down
19 changes: 12 additions & 7 deletions src/ninshiki_cpp/node/ninshiki_cpp_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,18 @@ void NinshikiCppNode::set_detection(

void NinshikiCppNode::set_image_msg()
{
this->image_msg->header.stamp = node->get_clock()->now();
this->image_msg->header.frame_id = "camera";
this->image_msg->width = received_frame.cols;
this->image_msg->height = received_frame.rows;
this->image_msg->encoding = "bgr8";
this->image_msg->data.assign(
received_frame.data, received_frame.data + received_frame.total() * received_frame.elemSize());
if (!this->image_msg)
{
this->image_msg = std::make_shared<sensor_msgs::msg::Image>();
}

this->cv_image.header.stamp = node->get_clock()->now();
this->cv_image.header.frame_id = "camera";
this->cv_image.encoding = "bgr8";
this->cv_image.image = received_frame;

// Convert to sensor_msgs::msg::Image
this->image_msg = this->cv_image.toImageMsg();
}

std::string NinshikiCppNode::get_node_prefix()
Expand Down

0 comments on commit f1e07fd

Please sign in to comment.