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

How do I toggle on/off my camera view in RViz through a parameter or message?

asked 2015-07-20 18:30:00 -0500

lahaela gravatar image

I have a camera set up in RViz using a gazebo simulation based on the urdf tutorials, which leaves the camera always on. I want to be able to press a key to toggle the camera on/off. I'm willing to accept hacks like zooming in to one black pixel or lowering the quality of the image until it's completely blurred. I'm also willing to change the camera to a second camera that's staring at a blank wall, so that a white or black pane shows up.

I've explored changing the zoom parameter of the camera from 1 to 1000, but it didn't do anything to affect the RViz Camera view (which remained at 1). I also tried using rosparam to change other parameters like image quality, but nothing actually changed in the image. I'm not sure how to change the topic the camera is subscribed to, for example to a static black image.

Do you have any suggestions?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-07-22 17:05:46 -0500

Ethan Robinson gravatar image

updated 2015-07-23 13:10:57 -0500

Original Question:

I'm working on this same issue and tried the solution you posted William. It seems like what I did should work, but when I republish the image data from the camera to a different topic (/displayed_image), the RVIZ camera view does not show the image, just a black screen. RVIZ doesn't even give out a warning, it shows that it is receiving the images. When I echo the topic data from /displayed_image, it seems like I get the same data as the actual camera topic. Any idea's as to why RVIZ is not correctly displaying my image?

Answer: Thanks to the suggestion of William and Dornhege, I figured out a workaround. The issue was actually something with rviz (not sure what), but when I use rosrun image_view image_view <image_topic> it correctly shows either the camera view image or the blank screen image depending on my mux settings. For future reference for anyone trying to do something similar:

  1. Run your gazebo model with the camera
  2. Run your blank screen publisher (code for mine is below)
  3. Setup the mux: rosrun topic_tools mux topic_to_publish_to camera_topic blank_screen_topic mux:=image_mux
  4. To switch between the selected images use: rosrun topic_tools mux_select image_mux image_topic_to_display
  5. You can also do this through service calls, I haven't yet, but see http://wiki.ros.org/topic_tools/mux for details.

"Preformatted text" won't allow me to select the whole code... it just takes bits and pieces if I try to do the whole thing. However, here is the important bit (this node is not terribly difficult anyway).

def blanker():

rospy.init_node('blank_screen')
pub=rospy.Publisher('blank_screen', Image, queue_size=10)
rate = rospy.Rate(1)

while not rospy.is_shutdown():
    img = Image()
    img.data = [0 for _ in range(800*3600)] # data
    img.height = 800
    img.width =1200
    img.step = 3600
    img.is_bigendian = 0
    img.encoding = "rgb8"
    img.header = Header()
    img.header.frame_id = "camera_link"
    img.header.stamp = rospy.Time.now()
    pub.publish(img)
    rate.sleep()
edit flag offensive delete link more

Comments

@Ethan Robinson This looks like a new question, please use a comment or ask a new question and link to it in a comment here.

William gravatar image William  ( 2015-07-22 18:59:02 -0500 )edit

Why doesn't your image_publish_callback function just do pub.publish(data)?

William gravatar image William  ( 2015-07-22 18:59:22 -0500 )edit

Also, I would go with @dornhege's suggestion and use mux ( http://wiki.ros.org/topic_tools/mux ) and a python script which sends service calls to that. It will operate much more efficiently since it does not deserialize the images it is multiplexing.

William gravatar image William  ( 2015-07-22 19:01:05 -0500 )edit

William, I'm on the same project with the OP which is why I added it here, but I can reask this as a new question if you think it would be better for the forum. I'll follow you and dornheges advice on using mux. Didn't understand its workings before which is why I did it manually.

Ethan Robinson gravatar image Ethan Robinson  ( 2015-07-22 19:40:17 -0500 )edit

I figured out the mux and correctly republished the camera's sensor_msgs/Image data onto a new topic I called /displayed_image, but I'm still getting the black screen problem like I was getting in my above post. Everything appears to be working (no error/warning messages) but no image is shown.

Ethan Robinson gravatar image Ethan Robinson  ( 2015-07-22 19:43:12 -0500 )edit

If you're on the same project, then I'd recommend rolling this answer into an edit of his question when ever he gets a chance. You can leave it as an answer until then. Or if you eventually get this script working you can update this "question posted as an answer" and make it an actual answer.

William gravatar image William  ( 2015-07-22 20:02:07 -0500 )edit
1

You can try to look at the image on /displayed_image using image_view to see if it is rviz, but I doubt it: rosrun image_view image_view image:=displayed_image

William gravatar image William  ( 2015-07-22 20:04:08 -0500 )edit

It actually ended up being rviz! Thanks for the image_view command. I had to fix a typo in my blank_screen publisher (different program than shown above) but using mux_select now works correctly to display the image I select. I'll update my answer with the fix.

Ethan Robinson gravatar image Ethan Robinson  ( 2015-07-23 12:36:01 -0500 )edit
3

answered 2015-07-20 19:49:49 -0500

William gravatar image

updated 2015-07-22 19:02:47 -0500

There is no ROS interface for controlling rviz's display properties. You could write a node which subscribed to the camera feed and normally just republished it to a new topic, and then on a Service call or button press it could change to publishing a blank image. Then you can subscribe rviz to the output topic of that node.

Edit:

I think @dornhege's suggestion is better, use mux ( http://wiki.ros.org/topic_tools/mux ) and a node which reads the key presses and sends service calls to mux in order to switch feeds.

edit flag offensive delete link more

Comments

2

http://wiki.ros.org/topic_tools/mux does that, although it uses a service to switch instead of parameter or message.

dornhege gravatar image dornhege  ( 2015-07-21 03:33:51 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-20 18:30:00 -0500

Seen: 1,268 times

Last updated: Jul 23 '15