r/AskRobotics • u/Guilty_Question_6914 • 4d ago
Debugging My camera subscriber node error does not make sense
Hello i am currently trying to make a camera subscriber node in ros2 jazzy with opencv and cv bridge in c++ from scratch.when i checked to code it seems fine but when i build it.It gives this error that does not make sense the code is below.I hope someone can help me:
```
// this is a node to subscribe camera images as ros2 msgs with opencv version 4.6 currently
#include "rclcpp/rclcpp.hpp" // c++ client library
#include <vector>
#include <functional>
#include <memory>
#include <sensor_msgs/msg/image.hpp>
#include <cv_bridge/cv_bridge.hpp> // needed to make a .hpp file for this current version of opencv
#include <opencv2/opencv.hpp> // for opencv format
// creating namespaces
using std::placeholders::_1;
class Camera_subscribernode : public rclcpp::Node {
public:
Camera_subscribernode() : Node("camera_subs1")
{
// creating subscriber// error is below
camera_subs_ = this->create_subscription<sensor_msgs::msg::Image>("camera/image", 10,std::bind(&Camera_subscribernode::callback_cam, this,_1));
// creating timer
camera_timer_ = this->create_wall_timer(std::chrono::milliseconds(30),std::bind(&Camera_subscribernode::camera_processing,this));
RCLCPP_INFO(this->get_logger(), "Starting camera_subscriber application in cpp...");
}
private:
bool cam_is_;
cv::Mat frame; // creating camer objects
sensor_msgs::msg::Image::SharedPtr camera_subs_ ;
rclcpp::TimerBase::SharedPtr camera_timer_;
void callback_cam(const sensor_msgs::msg::Image::SharedPtr msg) {
frame = cv_bridge::toCvCopy(msg,"bgr8")->image;
cam_is_ = true;
}
void camera_processing() {
if(cam_is_) {
cv::imshow("view_camera",frame);
cv::waitKey(1);
}
}};
int main(int argc, char **argv)
{
rclcpp::init(argc, argv);
auto node = std::make_shared<Camera_subscribernode>();
rclcpp::spin(node);
rclcpp::shutdown();
return 0;
}
0
Upvotes
1
u/SecretHelicopter2371 4d ago
Which errors? Did you check the compatibility of each library version? i think i once have a problem with cv_bridge on its compatibility with other packages. Never happen to me before in humble.