Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to update cv::namedwindow in multi-threading environment?

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 {
    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);
int main(int argc, char **argv)
  ros::init(argc, argv, "PredictiveDisplay");
  ros::NodeHandle nh;
  storedData obj;
  cv::namedWindow("view", 0);

  ros::Subscriber subIm = nh.subscribe("/image", 2, &storedData::imCallback, &obj);
  ros::Subscriber subDepth = nh.subscribe("/depth", 2, &storedData::depthCallback, &obj);

  ros::AsyncSpinner spinner(2);