If 1 callback receives an image and performs some image-processing. How can the output image be shown in multi-threading environment? By multi-threading I mean, if that particular callback(depthCallback) can be invoked by more than one thread.
And, one more query: Is using waitkey(1), optimal for real-time application?
class storedData {
public:
cv::Mat im, depth, outIm;
void imCallback(const sensor_msgs::CompressedImageConstPtr& msgIm) {
im = cv::imdecode(cv::Mat(msgIm->data),3);
}
void depthCallback(const sensor_msgs::CompressedImageConstPtr& msgDepth)
{
depth = cv::imdecode(cv::Mat(msgDepth->data),0);
// Performs something using both images(im & depth), Result : outIm //
cv::imshow("view", outIm);
cv::waitKey(1);
}
};
int main(int argc, char **argv)
{
ros::init(argc, argv, "PredictiveDisplay");
ros::NodeHandle nh;
storedData obj;
cv::namedWindow("view", 0);
cv::startWindowThread();
ros::Subscriber subIm = nh.subscribe("/image", 2, &storedData::imCallback, &obj);
ros::Subscriber subDepth = nh.subscribe("/depth", 2, &storedData::depthCallback, &obj);
ros::AsyncSpinner spinner(2);
spinner.start();
ros::waitForShutdown();
cv::destroyWindow("view");
}