Ask Your Question

Unable to open ".yml" file using cv::FileStorage in ROS Kinetic

asked 2016-11-01 20:48:12 -0500

timku gravatar image

I would like to retrieve the camera calibration parameters from "intrinsic.yml" and "extrinsic.yml" file and use the parameter to rectify the Infrared images from the Realsense R200 camera. I have tried using the opencv FileStorage method but the program is unable to open both files. Below is a portion of the code that I used to open and extract the parameters from the ".yml" file.

std::string intrinsic_filename = "intrinsics.yml";
std::string extrinsic_filename = "extrinsics.yml";

if( (!intrinsic_filename.empty()) ^ (!extrinsic_filename.empty()) )
            printf("Command-line parameter error: either both intrinsic and extrinsic parameters must be specified, or none of them (when the stereo pair is already rectified)\n");
            //return -1;

if( !intrinsic_filename.empty() )   // rectify and undistort images
        // reading intrinsic parameters
    cv::FileStorage fs(intrinsic_filename, cv::FileStorage::READ);
        printf("Failed to open file %s\n", intrinsic_filename.c_str());
        //return -1;

    cv::Mat M1, D1, M2, D2;
    fs["M1"] >> M1;
    fs["D1"] >> D1;
    fs["M2"] >> M2;
    fs["D2"] >> D2; 

    M1 *= scale;
    M2 *= scale;, cv::FileStorage::READ);
        printf("Failed to open file %s\n", extrinsic_filename.c_str());
        //return -1;

    cv::Mat R, T, R1, P1, R2, P2;
    fs["R"] >> R;
    fs["T"] >> T;
    fs["F"] >> F;

    //stereoRectify( M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q, 1024, -1, img_size, &roi1, &roi2 );

    cv::Mat map11, map12, map21, map22;
    //initUndistortRectifyMap(M1, D1, R1, P1, img_size, CV_16SC2, map11, map12);
    //initUndistortRectifyMap(M2, D2, R2, P2, img_size, CV_16SC2, map21, map22);

    //remap(src, img1r, map11, map12, 1);       // rectified image: img1r
    //remap(src, img2r, map21, map22, 1);       // rectified image: img2r

Both the "intrinsic.yml" and "extrinsic.yml" file are located at the package root location. The output that I get is as follows: "Failed to open file intrinsic.yml" and "Failed to open file extrinsic.yml". How do I go about solving this problem?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-11-02 06:27:40 -0500

gvdhoorn gravatar image

Your file paths are probably relative, so they will be resolved against the current working directory (CWD). The CWD for ROS nodes is not the root of the packages that they are located in, but the $HOME/.ros directory.

What is typically done in these cases is to use parameters to pass the absolute location of files to nodes, with the parameters getting set in a launch file. The launch file then allows you to use directives such as $(find ..), which will search for the package name that you give it, and return the absolute path to that.

See wiki/roslaunch/XML for more info on this. See wiki/roslaunch/XML - node - attributes for the cwd attribute for nodes (but note that you cannot change it to any arbitrary path).

edit flag offensive delete link more


I'm experimenting the same issue and the absolute path does not solve it. There is the same problem in this unsolved question.

Caba gravatar image Caba  ( 2017-09-05 14:20:39 -0500 )edit

Without more information from the OP it's a bit difficult to say whether it's "the same problem".

gvdhoorn gravatar image gvdhoorn  ( 2017-09-05 15:03:51 -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: 2016-11-01 20:48:12 -0500

Seen: 979 times

Last updated: Nov 02 '16