-
Notifications
You must be signed in to change notification settings - Fork 0
/
filestorage.cpp
42 lines (31 loc) · 956 Bytes
/
filestorage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <opencv2/opencv.hpp>
#include <sstream>
#include <string>
int SIDE = 256;
int PERIODOS = 8;
int main(int argc, char** argv) {
std::stringstream ss_img, ss_yml;
cv::Mat image;
ss_yml << "senoide-" << SIDE << ".yml";
image = cv::Mat::zeros(SIDE, SIDE, CV_32FC1);
cv::FileStorage fs(ss_yml.str(), cv::FileStorage::WRITE);
for (int i = 0; i < SIDE; i++) {
for (int j = 0; j < SIDE; j++) {
image.at<float>(i, j) = 127 * sin(2 * M_PI * PERIODOS * j / SIDE) + 128;
}
}
fs << "mat" << image;
fs.release();
cv::normalize(image, image, 0, 255, cv::NORM_MINMAX);
image.convertTo(image, CV_8U);
ss_img << "senoide-" << SIDE << ".png";
cv::imwrite(ss_img.str(), image);
fs.open(ss_yml.str(), cv::FileStorage::READ);
fs["mat"] >> image;
cv::normalize(image, image, 0, 255, cv::NORM_MINMAX);
image.convertTo(image, CV_8U);
cv::imshow("image", image);
cv::waitKey();
return 0;
}