使用.YAML文件

文件如图:
在这里插入图片描述使用方法:

#include <iostream>
#include <string>
#include<opencv2/core/core.hpp>
using namespace std;

int main(int argc, char **argv) {
	//读取
    string ConfigSLAMPath = "../ConfigSLAM.yaml";//把路径设置对
    cv::FileStorage fsSettings(ConfigSLAMPath.c_str(), 	//将配置文件名转换成为字符串
                               cv::FileStorage::READ);		//只读
    if (!fsSettings.isOpened()){
         cerr << "Failed to open settings file at: " << ConfigSLAMPath << endl;
         //然后退出
         exit(-1);
    }
    float fx = fsSettings["Camera.fx"];
    float fy = fsSettings["Camera.fy"];
    cout<<fx<<"-"<<fy<<endl;

	return 0;
}

使用YAML文件注意点:
我在使用的时候,因为文件有缩进,会报错(把缩进收回去就可以):

OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/yk/桌面/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/yk/桌面/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值