Ask Your Question
0

Mat pointer

asked 2017-04-24 23:41:38 -0500

Nbb gravatar image

How do I create a vector of Mat pointers ? In the code below, I want to read the yaml files into the matrices K_00, K_01, etc

    //initialize camera params
    cv::Mat K_00, K_01, D_00, D_01, R, Tr;  
    std::vector<cv::Mat>     camera_params      = {  K_00,   K_01,   D_00,   D_01,   R,   T };
    std::vector<std::string> camera_params_name = { "K_00", "K_01", "D_00", "D_01", "R", "T"};

    for (int i = 0; i < camera_params.size(); i++)
    {
        cv::FileStorage fs;
        fs.open(root + camera_params_name[i] + ".yaml", cv::FileStorage::READ);
        fs[camera_params_name[i]] >> camera_params[i];
    }

    //error K_00, K_01, etc. are all empty
    stereoRectify(K_00, cv::Mat(), K_01, ....); // I want to use K_00, etc. instead of 
                                                // camera_params[0]
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-04-25 12:03:24 -0500

matman gravatar image

updated 2017-04-25 12:07:02 -0500

Your Mats are reallocated when they are filled and camera_params[i] point to another Mat header. You should do something like this:

std::vector<cv::Mat>     camera_params;
std::vector<std::string> camera_params_name = { "K_00", "K_01", "D_00", "D_01", "R", "T"};

for (int i = 0; i < camera_params.size(); i++)
{
    cv::FileStorage fs;
    fs.open(root + camera_params_name[i] + ".yaml", cv::FileStorage::READ);
    cv::Mat tmp;
    fs[camera_params_name[i]] >> tmp;
    camera_params.push_back(tmp);
}

stereoRectify(camera_param[0], cv::Mat(), camera_param[1], ....);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-24 23:41:38 -0500

Seen: 431 times

Last updated: Apr 25 '17