Ask Your Question

Updated value in Parameter server not reflecting in real time Camera

asked 2019-03-28 05:55:50 -0500

Radeshwar gravatar image

updated 2019-03-28 14:18:18 -0500

jayess gravatar image

Hi all,

I am using two cameras and I have a .yaml file having the parameter list like fps, Width and length of the image, Pixels and few more.

I have created a parameter server and have stored the parameters to access it in real time.

The problem is that I am able to change the parameters in real time but is not getting reflected in the camera output feed.

For example...If my camera is producing output at 30 fps and I have changed my fps to 10 in real time so there is a significant difference between the fps but this is not being reflected in the output but my paramter server is getting updated.

How to update the camera parameters in real time.

I am using getParam() to read the values.

Below is my Publisher code.

#include "ros/ros.h"
#include "usb_cam/usb_cam.h"
#include "image_transport/image_transport.h"
#include "camera_info_manager/camera_info_manager.h"
#include "sstream"
#include <std_srvs/Empty.h>

 namespace usb_cam {

 class UsbCamNode
      // private ROS node handle
      ros::NodeHandle node_;
      // shared image message
      sensor_msgs::Image img_;
      image_transport::CameraPublisher image_pub_;
      // parameters
      std::string video_device_name_, io_method_name_, pixel_format_name_, camera_name_,           camera_info_url_;
       //std::string start_service_name_, start_service_name_;
       bool streaming_status_;
       int image_width_, image_height_, framerate_, exposure_, brightness_, contrast_, saturation_, sharpness_, focus_, white_balance_, gain_;
       bool autofocus_, autoexposure_, auto_white_balance_;
       boost::shared_ptr<camera_info_manager::CameraInfoManager> cinfo_;

       UsbCam cam_;

       ros::ServiceServer service_start_, service_stop_;
       bool service_start_cap(std_srvs::Empty::Request  &req, std_srvs::Empty::Response &res )
            return true;

       bool service_stop_cap( std_srvs::Empty::Request  &req, std_srvs::Empty::Response &res )
           return true;

       UsbCamNode() :
            // advertise the main image topic
            image_transport::ImageTransport it(node_);
            image_pub_ = it.advertiseCamera("image_raw", 0);

            // grab the parameters
            node_.param("video_device", video_device_name_, std::string("/dev/video0"));
            node_.param("brightness", brightness_, -1); //0-255, -1 "leave alone"
            node_.param("contrast", contrast_, -1); //0-255, -1 "leave alone"
            node_.param("saturation", saturation_, -1); //0-255, -1 "leave alone"
            node_.param("sharpness", sharpness_, -1); //0-255, -1 "leave alone"
            // possible values: mmap, read, userptr
            // node_.getParam("/io_method", io_method_name_, std::string("mmap"));
        node_.getParam("/io_method", io_method_name_);
            node_.getParam("/image_width", image_width_);
            node_.getParam("/image_height", image_height_);
            //node_.param("framerate", framerate_, 20);
            node_.getParam("/framerate", framerate_);

           // possible values: yuyv, uyvy, mjpeg, yuvmono10, rgb24
           // node_.param("/pixel_format", pixel_format_name_, std::string("mjpeg"));
       node_.getParam("/pixel_format", pixel_format_name_);
           // enable/disable autofocus
           // enable/disable autofocus
           node_.param("autofocus", autofocus_, false);
           node_.param("focus", focus_, -1); //0-255, -1 "leave alone"
           // enable/disable autoexposure
           node_.param("autoexposure", autoexposure_, true);
           node_.param("exposure", exposure_, 100);
           node_.param("gain", gain_, -1); //0-100?, -1 "leave alone"
           // enable/disable auto white balance temperature
           node_.param("auto_white_balance", auto_white_balance_, true);
           node_.param("white_balance", white_balance_, 4000);

           // load the camera info
           node_.param("camera_frame_id", img_.header.frame_id, std::string("head_camera"));
           node_.param("camera_name", camera_name_, std::string("head_camera"));
           node_.param("camera_info_url", camera_info_url_, std::string(""));
           cinfo_.reset(new camera_info_manager::CameraInfoManager(node_, camera_name_, camera_info_url_));

           // create Services
           service_start_ = node_.advertiseService("start_capture", &UsbCamNode::service_start_cap, this);
           service_stop_ = node_.advertiseService("stop_capture", &UsbCamNode::service_stop_cap, this);

           // check for default camera info
           if (!cinfo_->isCalibrated())
                sensor_msgs::CameraInfo camera_info;
                camera_info.header.frame_id = img_.header.frame_id;
                camera_info.width = image_width_;
                camera_info.height = image_height_;
                cinfo_- ...
edit retag flag offensive close merge delete



Please take 5 minutes to properly format your code. As-is, this is unreadable. There are plenty of websites available that run your code through a code pretty printer. I'd recommend to use one of those.

gvdhoorn gravatar image gvdhoorn  ( 2019-03-28 06:02:46 -0500 )edit

Thanks you for your advice....I have formatted my code. Kindly do the needful.

Radeshwar gravatar image Radeshwar  ( 2019-03-28 08:47:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-03-28 22:31:33 -0500

ahendrix gravatar image

I don't see anything immediately wrong with your code, but there are a few pieces that are missing:

  1. How are you setting params? I notice that you're using global params in some places, and private parms in others.
  2. I see that you have a ROS_INFO to print the frame rate during every capture. Does that value change when you change the framerate parameter? If that value updates, it means that your parameter code is working. If it doesn't update, it means that there's something wrong with the way you're setting or getting parameters.
  3. In general, it looks like you have some good logging statements in your code. It would be very useful to see part of the output (2-3 frames before and 4-5 frames after you try to change the frame rate)
edit flag offensive delete link more



  1. I have a yaml file where all the parameters have been set and when the node publishes the data it takes those parameters. The camera feed is running with this settings only throughout the code regardless of any change in my Parameter Server in real time.

  2. When I use setParam() command to set any parameter I am able to see parameter update in my Parameter Server as well however my problem is these changes are not getting reflected in my video output.

For eg: Consider my camera is publishing the video feed at 30 fps and I have set my new frame rate to 5 using setParam(). My Parameter Server is updated to new value but my output video is still running at 30 fps. I don't see the change happening in real time though it has got updated in my Parameter Server.

Radeshwar gravatar image Radeshwar  ( 2019-03-29 00:09:55 -0500 )edit

I believe that, just before publishing the video feed image_pub_.publish(img_, *ci);

If I am able to update these parameters and then publish, my issue should be solved. Correct me if I am wrong.

Radeshwar gravatar image Radeshwar  ( 2019-03-29 00:23:36 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-03-28 05:55:50 -0500

Seen: 259 times

Last updated: Mar 28 '19