关闭

opencv代码段2

标签: opencvvim
264人阅读 评论(0) 收藏 举报
分类:

读写配置文件

filestorage.cpp

#include <opencv2/opencv.hpp>
#include <string>
#include <iostream>

using namespace std;

int main( int argc, char **argv )
{
    if(argc!=2){
        cerr << "Usage: ./filestorage <file_path>" << endl;
        return 1;
    }

    string strSettingPath(argv[1]);

    // read 
    cv::FileStorage fRead(strSettingPath, cv::FileStorage::READ);
    float a = fRead["A"];
    float b = fRead["B"];
    float c = fRead["C"];
    float d = fRead["D"];

    cout << a << endl; 
    cout << b << endl; 
    cout << c << endl; 
    cout << d << endl; 

    // append (w+)
    cv::FileStorage fWrite(strSettingPath, cv::FileStorage::APPEND);
    cv::write(fWrite, "INSERT", 10000);
    cout << "write successfully" << endl;

    return 0;
}

setting.yaml

%YAML:1.0
A: 1
B: 2
C: 3
D: 4

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(filestorage)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -std=c++11")

find_package( OpenCV REQUIRED )
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable( filestorage filestorage.cpp)
target_link_libraries( filestorage ${OpenCV_LIBS})

vim全局替换

1,$s/str1/str2/g

1表示从第一行开始查找
s表示替换
str1是替换前的字符串
str2是替换后的字符串
g表示一行中所有都替换,不加则只会替换第一个匹配的。即贪婪和非贪婪的区别

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场