-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBscanFFTxml2ms.cpp
163 lines (125 loc) · 3.33 KB
/
BscanFFTxml2ms.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifdef _WIN64
#include "stdafx.h"
#include "windows.h"
// anything before a precompiled header is ignored,
// so no endif here! add #endif to compile on __unix__ !
#endif
/*
*
* Opens OpenCV FileStorage xml file, saves data as matlab compatible m file
* adapted for BscanFFT from OpenCVxml2m
* changed to output multiple files.
*
* Hari Nandakumar
* 27 Dec 2018
*/
//#define _WIN64
//#define __unix__
#include <stdio.h>
#include <stdlib.h>
#ifdef __unix__
#include <unistd.h>
#endif
#include <fstream>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
// this is for mkdir
#include <opencv2/opencv.hpp>
int main()
{
// using idea from
// https://stackoverflow.com/questions/27697451/how-to-convert-an-opencv-mat-that-has-been-written-in-an-xml-file-back-into-an-i/
cv::Mat m, bscan;
int camgain, camtime, normfactor;
cv::FileStorage fs("BscanFFT.xml", cv::FileStorage::READ);
std::ofstream outfile("BscanFFTxml2m.m");
char stringvar[80];
char stringvar2[80];
fs["camgain"] >> camgain;
fs["camtime"] >> camtime;
//fs["normfactor"] >> normfactor;
//fs["bscan001"] >> bscan;
for (int indexi = 1; indexi<101; indexi++)
{
sprintf(stringvar, "bscan%03d", indexi);
sprintf(stringvar2, "BscanFFTxml2mb%03d.m", indexi);
if (!fs[stringvar].isNone())
{
std::ofstream outfile2(stringvar2);
fs[stringvar] >> m;
outfile2 << "bscan";
//outfile2 << indexi;
outfile2 << "=";
outfile2 << m;
outfile2 << ";" << std::endl;
}
sprintf(stringvar, "linearized%03d", indexi);
sprintf(stringvar2, "BscanFFTxml2mlin%03d.m", indexi);
if (!fs[stringvar].isNone())
{
std::ofstream outfile2(stringvar2);
fs[stringvar] >> m;
outfile2 << "linearized";
//outfile2 << indexi;
outfile2 << "=";
outfile2 << m;
outfile2 << ";" << std::endl;
}
sprintf(stringvar, "bscanman%03d", indexi);
sprintf(stringvar2, "BscanFFTxml2mbman%03d.m", indexi);
if (!fs[stringvar].isNone())
{
std::ofstream outfile2(stringvar2);
fs[stringvar] >> m;
outfile2 << "bscanman";
//outfile2 << indexi;
outfile2 << "=";
outfile2 << m;
outfile2 << ";" << std::endl;
}
sprintf(stringvar, "bscansub%03d", indexi);
sprintf(stringvar2, "BscanFFTxml2mbsub%03d.m", indexi);
if (!fs[stringvar].isNone())
{
std::ofstream outfile2(stringvar2);
fs[stringvar] >> m;
outfile2 << "bscansub";
//outfile2 << indexi;
outfile2 << "=";
outfile2 << m;
outfile2 << ";" << std::endl;
}
sprintf(stringvar, "jscan%03d", indexi);
sprintf(stringvar2, "BscanFFTxml2mj%03d.m", indexi);
if (!fs[stringvar].isNone())
{
std::ofstream outfile2(stringvar2);
fs[stringvar] >> m;
outfile2 << "jscan";
//outfile2 << indexi;
outfile2 << "=";
outfile2 << m;
outfile2 << ";" << std::endl;
}
sprintf(stringvar, "vibrprof%03d", indexi);
sprintf(stringvar2, "BscanFFTxml2mvibr%03d.m", indexi);
if (!fs[stringvar].isNone())
{
std::ofstream outfile2(stringvar2);
fs[stringvar] >> m;
outfile2 << "vibrprof";
//outfile2 << indexi;
outfile2 << "=";
outfile2 << m;
outfile2 << ";" << std::endl;
}
}
outfile << "camgain=";
outfile << camgain;
outfile << ";" << std::endl;
outfile << "camtime=";
outfile << camtime;
outfile << ";" << std::endl;
return 0;
}