I have a function where instead of returning a cv::Mat
I want to pass in a reference to an existing data structure. I am trying to reduce unnecessary copying of cv::Mat
Function currently looks like:
cv::Mat HSV::apply(const cv::Mat& input) {
cv::Mat image, output;
cv::cvtColor(input, image, cv::COLOR_BGR2HSV);
cv::inRange(image, m_Low, m_High, output);
return output;
}
I am trying to convert it to -
void HSV::apply(const cv::Mat& input) {
cv::Mat image, output;
cv::cvtColor(input, image, cv::COLOR_BGR2HSV);
cv::inRange(image, m_Low, m_High, output);
}
Now in another node, I used to call this function as follows:
Detection::Detection(ros::NodeHandle& nh)
: m_Filter_(std::make_unique<HSV>()), {
m_ImageSub = nh.subscribe("/image_raw", 10, &Detector::inputCb, this);
}
void Detector::inputCb(const sensor_msgs::Image::ConstPtr& msg) {
cv::Mat image = ImageConverter::convertToCvMat(msg);
cv::Mat finalImage = m_Filter_->apply(image);
}
How can I call the function now if I am passing it by reference?