[英]ROS cv_bridge ImagePtr conversion in c++ string
Below code snippet from ros subscriber node where video image frame is subscribed based on topic and displayed. 来自ros订阅者节点的代码片段,其中视频图像帧基于主题订阅并显示。 As per my requirement cv_ptr->image needs to be converted in to c++ string so that I can create byte array(vector ) out of that .
根据我的要求,cv_ptr-> image需要转换为c ++字符串,以便我可以创建字节数组(向量)。
void imageCb(const sensor_msgs::ImageConstPtr& msg)
{
cv_bridge::CvImagePtr cv_ptr;
try
{
cv_ptr = cv_bridge::toCvCopy(msg, enc::BGR8);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
return;
}
if (cv_ptr->image.rows > 60 && cv_ptr->image.cols > 60)
cv::circle(cv_ptr->image, cv::Point(50, 50), 10, CV_RGB(255,0,0));
cv::imshow(WINDOW, cv_ptr->image);
cv::waitKey(3);
}
basically I am looking for API which converts cv_ptr->image frame buffer in c++ string .After subscribing image based on topic , I need to convert the same in byte array so that it can be inserted in activemqcpp producer as other end activemqjava subscriber is expecting the same in bytestream format. 基本上我正在寻找在c ++字符串中转换cv_ptr->图像帧缓冲的API。在根据主题订阅图像之后,我需要转换相同的字节数组,以便它可以插入到activemqcpp生成器中,因为其他端activemqjava订阅者期待字节流格式相同。
string img_string = (copy operation) cv_ptr->image;// Not sure how to copy this buffer in c++ string
vector <unsigned char> vec(img_string.begin().img_string.end());
below is the class specification as per cv_bridge.h file. 下面是根据cv_bridge.h文件的类规范。
class CvImage;
typedef boost::shared_ptr<CvImage> CvImagePtr;
typedef boost::shared_ptr<CvImage const> CvImageConstPtr;
class CvImage
{
public:
std_msgs::Header header;
std::string encoding;
cv::Mat image;
sensor_msgs::ImagePtr toImageMsg() const;
void toImageMsg(sensor_msgs::Image& ros_image) const;
typedef boost::shared_ptr<CvImage> Ptr;
typedef boost::shared_ptr<CvImage const> ConstPtr;
};
Can anybody suggest how to achieve the same in roscpp? 任何人都可以建议如何在roscpp中实现相同的目标?
As specified here http://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html#a4d33bed1c850265370d2af0ff02e1564 OpenCV's Mat class already stores image data as unsigned char array. 正如此处所述http://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html#a4d33bed1c850265370d2af0ff02e1564 OpenCV的Mat类已经将图像数据存储为unsigned char数组。
The type of cv_ptr->image
is already cv::Mat
. cv_ptr->image
的类型已经是cv::Mat
。
All you need to do access its contents like cv_ptr->image.data
所有你需要访问的内容,如
cv_ptr->image.data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.