Rosanswers logo

Hi everyone,

Currently, I'm trying to use C++ to deal with the image process with the Baxter hand camera. Inside the example ROS node in line 8 the static const std::string OPENCV_WINDOW = "Image window"; What is this program line use for? It's necessary to have this?

Another question is that does anyone know any good example can teach me about how subscribe the hand camera image topic?

Thank you so much.

Originally posted by Zero on ROS Answers with karma: 104 on 2016-07-12

Post score: 0


1 Answer 1


Rosanswers logo


That line simply defines a string called OPENCV_WINDOW with value "Image window". It is just the name of the OpenCV window that is opened in line 26.


If you look at the OpenCV documentation here, you can understand what the namedWindow() method does. To quote it, "The function namedWindow creates a window that can be used as a placeholder for images and trackbars. Created windows are referred to by their names."

So you can use the string "Image window" (the value of OPENCV_WINDOW string variable) to refer to this window. Eg : Line 31


This line is used to close the window opened in line 26.

You don't HAVE TO declare a string variable. You can simply open and close the window like this.

cv::namedWindow("Image window");

cv::destroyWindow("Image window");

However, it is a good practice to define these kind of values at the top of your code so that if you ever want to change it to something else (say, "Image window 1"), you don't have to comb through your code looking for all appearances of it. If it were me, I would have set it as a constant string so that I (or anyone else) accidentally (or intentionally) can't change the value somewhere else (can lead to very hard to debug bugs).

As for a good tutorial to subscribe to a topic, once you identify the topic you need to subscribe to, look at the roscpp documentation on subscribers and publishers here.

Originally posted by janindu with karma: 849 on 2016-07-13

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by Zero on 2016-07-13:
Hi Janindu,

Thank you for answering my question! Now I can much understand what's the program trying to do.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.