Ask Your Question
0

Print the Camera parameters from the file created after Camera Calibration

asked 2014-03-16 08:18:47 -0500

rosqueries gravatar image

updated 2014-03-16 08:55:57 -0500

I have calibrated my monocular camera using the ROS Tutorial. After calibrating the camera, a .yaml file got created which contains the various parameters of the camera.

Task: I want to print the coordinated of the center which are stored in .yml file. I think that i can do so by subscribing the camera parameter info but i don't know how can i do so?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-03-16 11:16:15 -0500

davinci gravatar image
rostopic echo /camera/camera_info

Change 'camera' to your camera name. This is really basic tutorial level stuff btw.

edit flag offensive delete link more

Comments

i want to get the parameters in my program. For example i want to print them using cout<<focal_lenght<<center_x<<center_y;< p="">

rosqueries gravatar image rosqueries  ( 2014-03-16 11:56:48 -0500 )edit

So, how do i get them into variable in C++ program

rosqueries gravatar image rosqueries  ( 2014-03-16 11:58:34 -0500 )edit

See the publish / subscriber tutorial for creating a subscriber to a topic. Change the topic to the camera info topic.

davinci gravatar image davinci  ( 2014-03-17 03:25:08 -0500 )edit
0

answered 2014-03-16 14:58:34 -0500

Joao Ferreira gravatar image

updated 2014-03-17 01:00:58 -0500

You got to create a function that reads the parameters.

For instance:

void readParams(const ros::NodeHandle& nh)
{
        nh.param<std::string>("ns" , ns , "custom_image");
        nh.param<double>("/"+ns+"/color/a" , color_a , 1.0);
        nh.param<double>("/"+ns+"/color/b" , color_b , 0.0);
        nh.param<double>("/"+ns+"/color/g" , color_g , 0.0);
        nh.param<double>("/"+ns+"/color/r" , color_r , 1.0);
}

The example above is reading color parameters, where the following parameters:

ns , color_a ,color_b , color_g , color_r

are declared in a .yaml file as follows:

# Node namespace
ns: 'custom_image'

# color parameters
color: { 'r': 1.0, 'g': 0.0, 'b': 0.0, 'a': 1.0 }

Thus, nh.param() is a function that receives three arguments:

argument 1 is a string with the name of the parameter as it appears to your ros environment.

argument 2 is a global variable that you should have declared prior to call this function. In this example, ns is a string variable, and color_a , color_b , color_g and color_r are double.

argument 3 is a default value that will be parsed to your variable (argument 2) just in case the parameter declared (argument 1) cannot be found.

In summary, as long as your parameters are visible in your ros environment, this function will read it by looking for argument 1, and store its value to the variable in argument 2.


Now that you have your readParams() function. You only have to call it parsing your node handle.

For instance, in my main() function I did:

    ros::init(argc , argv , "custom_image");
    ROS_INFO("Initializing my node...");

    ros::NodeHandle nh;
    readParams(nh);

After that, you can print the variables' values, as they are storing their respective parameters.

(If you need more help, take a look at: http://wiki.ros.org/roscpp/Overview/P... )

edit flag offensive delete link more

Comments

i want to know the focal length, center_x, center_y. Can't i get those things by "subscribing" to the ROS topic which publish them from the `.yaml` file. For example, something like camera_info topic

rosqueries gravatar image rosqueries  ( 2014-03-17 00:48:11 -0500 )edit

The .yaml file does not publish any topic. It does only provide these parameters to the parameters' server, so the ROS nodes can use them. That is why you can't subscribe. Also, I don't get the point of reading from a topic, as reading from the parameters's server is not that difficult.

Joao Ferreira gravatar image Joao Ferreira  ( 2014-03-17 00:56:50 -0500 )edit

can you tell me, where can i find the `.yaml` file to have a look on it so that i can search the name of parameters that i need. When i run the webcam, it searches for that file in "\home\USER\.ros....etc" but i cannot find the folder ".ros"

rosqueries gravatar image rosqueries  ( 2014-03-17 02:35:42 -0500 )edit

You can find the .yaml file by taking a look at the .launch file. For instance, in my .launch file, there is something like that: rosparam file="$(find custom_image)/params/marker_params.yaml" command="load" /> Thus, my .yaml file is inside a folder called "params" in my package directory.

Joao Ferreira gravatar image Joao Ferreira  ( 2014-03-17 02:41:42 -0500 )edit

No, but i have not moved the .yaml file to any other location yet. It was saved at its default location the Camera calibration GUI of ROS.

rosqueries gravatar image rosqueries  ( 2014-03-17 02:44:04 -0500 )edit

but the parameters name are also listed when you run "$ rosparam list" after launching your nodes. When you have only 'roscore' running, for example, and you run "$rosparam list" you get something like that: /rosdistro /roslaunch/uris/host_joao_inspiron_n5010__50954 /rosversion /run_id

Joao Ferreira gravatar image Joao Ferreira  ( 2014-03-17 02:44:19 -0500 )edit

Well, I have never used this camera_calibration package. Is there any .launch file? Does it create parameters?

Joao Ferreira gravatar image Joao Ferreira  ( 2014-03-17 02:48:07 -0500 )edit

I took a better look at the tutorial you are following. Section 1.7 talks about how to create your .yaml file from the parameters you have just commited to your camera. In order to be able to read parameters, you got to create this .yaml file, and use this file when you run/launch your node(s). When I first answered your question, I assumed you had the parameters being published already.

Joao Ferreira gravatar image Joao Ferreira  ( 2014-03-17 03:05:37 -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

Stats

Asked: 2014-03-16 08:18:47 -0500

Seen: 771 times

Last updated: Mar 17 '14