Last active
August 29, 2015 14:11
-
-
Save atinfinity/c1f7ea24844b0980db83 to your computer and use it in GitHub Desktop.
YAML入出力サンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
#include <iostream> | |
int main(int argc, const char* argv[]) | |
{ | |
// 画像を読み込む | |
cv::Mat src1 = cv::imread("lena.jpg", cv::IMREAD_COLOR); | |
// MatのデータをYAML形式のファイルに書き出す | |
cv::FileStorage fs_write("lena.yml", cv::FileStorage::WRITE); | |
if(!fs_write.isOpened()) | |
{ | |
std::cerr << "Failed to open YAML file." << std::endl; | |
return -1; | |
} | |
fs_write << "img" << src1; | |
fs_write.release(); | |
// YAML形式のファイルを読み込んでMatのデータにする | |
cv::Mat src2; | |
cv::FileStorage fs_read("lena.yml", cv::FileStorage::READ); | |
if(!fs_read.isOpened()) | |
{ | |
std::cerr << "Failed to open YAML file." << std::endl; | |
return -1; | |
} | |
fs_read["img"] >> src2; | |
fs_read.release(); | |
// 画像を表示する | |
cv::namedWindow("src1", cv::WINDOW_AUTOSIZE); | |
cv::namedWindow("src2", cv::WINDOW_AUTOSIZE); | |
cv::imshow("src1", src1); | |
cv::imshow("src2", src2); | |
cv::waitKey(0); | |
cv::destroyAllWindows(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment