ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

question in cv_bridge tutorials

asked 2016-07-12 00:28:50 -0600

Zero gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-07-13 02:17:15 -0600

janindu gravatar image

updated 2016-07-13 02:22:44 -0600

Hi,

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.

cv::namedWindow(OPENCV_WINDOW);

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

cv::destroyWindow(OPENCV_WINDOW);

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.

edit flag offensive delete link more

Comments

Hi Janindu,

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

Zero gravatar image Zero  ( 2016-07-13 02:37:40 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-12 00:28:50 -0600

Seen: 260 times

Last updated: Jul 13 '16