I need help with an error when run an OpenCV program
I am sorry if my subject is not clear but I am not sure how to describe this problem. Below is the error I receive when I try to run my node:
ubuntu@tegra-ubuntu:~/Documents/WorkSpaceOpenCV$ rosrun img_processor img_processor
img_processor: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = cv_bridge::CvImage; typename boost::detail::sp_member_access<T>::type = cv_bridge::CvImage*]: Assertion `px != 0' failed.
Aborted
I have 2 nodes. One is /camera which collect data from webcam and publish as /camera/raw_image.This run fine and I can see the image using image_viewer. Another node subscribes to /camera/raw_image and convert raw_image to hsv_image. I got error when I ran this node. You can see the code of my node below. Another question I have is even it abort the node, the rqt_graph still show this node run but with a red circle around it: screenshot_img_processor.png I am not sure what does it mean. I am new to ROS + OpenCV + C++
#include <ros/ros.h>
#include <sensor_msgs/image_encodings.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <math.h>
class Process_hsv
{
protected:
ros::NodeHandle nh;
image_transport::ImageTransport it;
image_transport::Publisher image_pub;
image_transport::Subscriber image_sub;
public:
Process_hsv(ros::NodeHandle & nh):nh(nh), it(nh)
{
//Advertise image messages to a topic
image_pub = it.advertise("/process_hsv/output_image",1);
//Listen for image messages on a topic and setup callback
image_sub = it.subscribe("/camera/image_raw",1,&Process_hsv::imageCallback,this);
// Open HighGUI Window
cv::namedWindow("hsv");
}
~Process_hsv()
{
cv::destroyWindow("hsv");
}
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
cv_bridge::CvImagePtr cv_ptr_in,cv_ptr_out;
cv::Mat img_in, img_hsv;
//Convert ROS iput image message to CV image by using cv_bridge
try
{
cv_ptr_in = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
img_in = cv_ptr_in->image;
}
catch(cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
}
//Convert input img from BGR to HSV
cv::cvtColor(img_in, img_hsv, CV_BGR2HSV);
//Display HSV Image in HighGUI window
cv::imshow("hsv",img_hsv);
//Needed to keep the HighGUI Window open
cv::waitKey(3);
//Convert cv::Mat to IplImage
cv_ptr_out->image = img_hsv;
//Convert CV image to ROS output image message and publish
try
{
image_pub.publish(cv_ptr_out->toImageMsg());
}
catch(cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
}
}
};
int main (int argc, char **argv)
{
//Initialize ROS Node
ros::init(argc, argv, "image_processor");
// Start node and create a Node Handler
ros::NodeHandle nh;
Process_hsv process_hsv(nh);
ros::spin();
return 0;
}