我想将rgb和深度两个图像混合起来寻找它们之间的转换。 这是我的程序,只是使用ros编程的基础
让我很容易理解 #include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
using namespace cv;
cv_bridge::CvImagePtr cv_ptr_rgb;
void imageCallbackrgb(const sensor_msgs::ImageConstPtr& msg)
{
//cv_bridge::CvImagePtr cv_ptr_rgb;
try
{
cv_ptr_rgb = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::MONO8);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
return;
}
//cv::imshow("OpenCV viewer Kinect RGB", cv_ptr_rgb->image);
cvWaitKey(3);
}
void imageCallbackdepth(const sensor_msgs::ImageConstPtr& msg)
{
// convert message from ROS to openCV
cv_bridge::CvImagePtr cv_ptr_depth;
try
{
cv_ptr_depth = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_16UC1);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
return;
}
//conversion 16UC to 8UC
/*
Conversion Sutffs
*/
/*
//*******************************blending two images*************************************
double alpha = 0.5; double beta;
beta = ( 1.0 - alpha );
Mat dst;
addWeighted( cv_ptr_rgb->image, alpha, image_8CU, 0.5, 0.5, dst);
cv::imshow( "Linear Blend", dst );
//**************************************************************************************
*/
cv::imshow("OpenCV viewer Kinect RGB", cv_ptr_rgb->image);
//cv::imshow("OpenCV viewer Kinect depth", image8U);
cvWaitKey(3);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listenerKinectuEye");
ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::Subscriber subkirgb = it.subscribe("/camera/rgb/image_color", 1, imageCallbackrgb);
image_transport::Subscriber subkidepth = it.subscribe("/camera/depth_registered/image_raw", 1, imageCallbackdepth);
ROS_INFO("subscribed to Kinect and uEye topics");
ros::spin();
}
这是我得到的错误(sub_node是我的可执行文件):
sub_node: /usr/include/boost/smart_ptr/shared_ptr.hpp:418:
T* boost::shared_ptr<T>::operator->() const [with T = cv_bridge::CvImage]: Assertion `px != 0' failed.
Aborted (core dumped)
错误来自我在imageCallbackdepth中使用的指针cv_ptr_rgb,因为即使我尝试
cv::imshow("OpenCV viewer Kinect RGB", cv_ptr_rgb->image);
在进行任何混合之前,我得到了同样的错误。
如何解决这个问题?