Use CVbridge to save ROS messages into Mat variable
I trying to use CVbridge to save ROS messages into mat variables, such that other function function can use that Mat variable to perform Vision related stuff..
But every time i use the cv_bridge::CvImagePtr cv_ptr->image
I get an assertion error saying:
main: /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 = const cv_bridge::CvImage; typename boost::detail::sp_member_access<T>::type = const cv_bridge::CvImage*]: Assertion `px != 0' failed.
Aborted (core dumped)
My callback function for conversion Ros messages to OpenCV images looks like this.
void ImageConverter::imageDetect(const sensor_msgs::ImageConstPtr& msg)
{
try
{
cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
return;
}
cout << "I am out" << endl;
frame = cv_ptr->image;
}
the frame is of type mat..
How do i make so other function, within the class , can use this Mat?..
Please post some more code! where is your
cv_ptr
defined?Could you solve this problem? I am currently facing the same error. :/