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

A display question about Opencv&ROS

asked 2014-08-05 22:00:29 -0500

Lau gravatar image

Hello , I am learning how to use OpenCV in ROS recently , now I meet a question about display the image . Here is my code :

ROS_INFO_STREAM("node1");
cv::namedWindow("test",1);
ROS_INFO_STREAM("node2");

But after I run the code , there is not window display . The terminal just print these information :

[ INFO] [1407293765.605951849]: node1
[ INFO] [1407293765.629249378]: node2

I can not understand why . Can you help me ? Thank you !

edit retag flag offensive close merge delete

Comments

does it show when you add cd::waitKey(0); after cv::namedWindow ?

Mehdi. gravatar image Mehdi.  ( 2014-08-05 23:53:50 -0500 )edit

Yes , It occurs . But why ? I wrote " ros::spin() " at the end of "int main(...) ", does the code running in a loop ?

Lau gravatar image Lau  ( 2014-08-06 02:33:01 -0500 )edit
Lau gravatar image Lau  ( 2014-08-06 02:49:03 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-08-06 04:09:00 -0500

Mehdi. gravatar image

If you check the code, image_converter.cpp the images are shown in line 53

  51     // Update GUI Window
  52     cv::imshow(OPENCV_WINDOW, cv_ptr->image);
  53     cv::waitKey(3);

cv::waitKey handles any windowing events, such as creating windows or showing images. if you call cv::imshow() in a loop through video frames, without following up each draw with cv::waitKey(3) nothing appears on screen, because highgui is never given time to process the draw requests from cv::imshow(). If you insist on showing an empty window before getting the images add

cv::waitKey(3);

after

cv::namedWindow("test",1);

you can replace 3 by any other small number, it expresses how long opencv should wait in milliseconds.

edit flag offensive delete link more

Comments

Yes , the window occurred . Thank you . Maybe it should wait for several ms after imshow or namedwindow in Linux . I never met this problem in win7 with VS or QtCreator .

Lau gravatar image Lau  ( 2014-08-06 05:54:44 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-08-05 22:00:29 -0500

Seen: 524 times

Last updated: Aug 06 '14