質問編集履歴

1

ソースコードの記載

2018/08/08 00:49

投稿

nanameko
nanameko

スコア17

test CHANGED
File without changes
test CHANGED
@@ -9,3 +9,273 @@
9
9
  int*とintの値を比べる方法を教えていただきたいです。
10
10
 
11
11
  よろしくおねがいします
12
+
13
+
14
+
15
+ ###ソースコード
16
+
17
+ ```lang-C++
18
+
19
+ #include <fstream> //ファイル読み込み用
20
+
21
+ #include <iostream> //ファイル読み込み用
22
+
23
+ #include <string> //String型使用をする用
24
+
25
+ #include <opencv2/opencv.hpp> //画像サイズ取得用
26
+
27
+ #include <stdio.h> //タイトルバー設定用
28
+
29
+ #include <windows.h> //タイトルバー設定用
30
+
31
+ #include <vector> //可変長配列使用をする用
32
+
33
+ #include <sstream> //stoi用(stringからint)
34
+
35
+ #include <stdint.h>//intptr_t用(ポインタ)
36
+
37
+ using namespace std;
38
+
39
+
40
+
41
+ const int imgnum = 7600;
42
+
43
+ string strdata[7600];
44
+
45
+
46
+
47
+ string imgdata_pass[7600];
48
+
49
+ int imgdata_box[7600][15][4];
50
+
51
+ int imgdata_size[7600][2];
52
+
53
+
54
+
55
+ int road()//読み込み関数
56
+
57
+ {
58
+
59
+ ifstream ifs("annotation.txt");
60
+
61
+ string str;
62
+
63
+ if (ifs.fail())
64
+
65
+ {
66
+
67
+ cerr << "リストファイルが読み込めません" << endl;
68
+
69
+ return -1;
70
+
71
+ }
72
+
73
+ int i = 0;
74
+
75
+ while (getline(ifs, str))
76
+
77
+ {
78
+
79
+ strdata[i] = str;
80
+
81
+ cout << "[" << strdata[i] << "]" << endl;
82
+
83
+ ::SetConsoleTitle(TEXT("リスト読み込み中"));
84
+
85
+ i++;
86
+
87
+ }
88
+
89
+ return 0;
90
+
91
+ }
92
+
93
+
94
+
95
+
96
+
97
+ vector<string> split(const string &str, char sep)//分割関数
98
+
99
+ {
100
+
101
+ vector<string> v;
102
+
103
+ stringstream ss(str);
104
+
105
+ string buffer;
106
+
107
+ while (getline(ss, buffer, sep))
108
+
109
+ {
110
+
111
+ v.push_back(buffer);
112
+
113
+ }
114
+
115
+ return v;
116
+
117
+ }
118
+
119
+
120
+
121
+ int analysis()//解析関数
122
+
123
+ {
124
+
125
+ ::SetConsoleTitle(TEXT("リスト解析中"));
126
+
127
+ int a = 0;
128
+
129
+ int b[4] = { 0,0,0,0 };
130
+
131
+ for (int i = 0; i < imgnum; i++)
132
+
133
+ {
134
+
135
+ vector<string> v = split(strdata[i], ' ');
136
+
137
+ imgdata_pass[i] = v[0];//画像パス代入
138
+
139
+ a = stoi(v[1]);
140
+
141
+ for (int j=0;j<a;j++)
142
+
143
+ {
144
+
145
+ b[0] = stoi(v[j*5+2]);//string型をint型に変換
146
+
147
+ b[1] = stoi(v[j * 5 + 3]);
148
+
149
+ b[2] = stoi(v[j * 5 + 4]);
150
+
151
+ b[3] = stoi(v[j * 5 + 5]);
152
+
153
+
154
+
155
+ imgdata_box[i][j][0] = b[0];//短形情報を代入
156
+
157
+ imgdata_box[i][j][1] = b[1];
158
+
159
+ imgdata_box[i][j][2] = b[2];
160
+
161
+ imgdata_box[i][j][3] = b[3];
162
+
163
+ }
164
+
165
+ }
166
+
167
+
168
+
169
+ return 0;
170
+
171
+ }
172
+
173
+
174
+
175
+ int count(int num) {//要素数カウント
176
+
177
+
178
+
179
+ int count = 0;
180
+
181
+ for (int i; i < 13; i++) {
182
+
183
+ if (imgdata_box[num][i][2] != NULL)
184
+
185
+ {
186
+
187
+ count++;
188
+
189
+ }
190
+
191
+ }
192
+
193
+ return count;
194
+
195
+ }
196
+
197
+
198
+
199
+ int trimming()//情報修正関数 OpenCV使用
200
+
201
+ {
202
+
203
+ //画像のサイズを取得
204
+
205
+ ::SetConsoleTitle(TEXT("リスト修正中"));
206
+
207
+ for (int i = 0; i < imgnum; i++)
208
+
209
+ {
210
+
211
+ cv::Mat img = cv::imread(imgdata_pass[i]);
212
+
213
+ if (img.empty()) {
214
+
215
+ cout << "画像が読み込めません" << endl;
216
+
217
+ return 1;
218
+
219
+ }
220
+
221
+ imgdata_size[i][1] = img.rows;//縦
222
+
223
+ imgdata_size[i][0] = img.cols;//横
224
+
225
+ }
226
+
227
+
228
+
229
+ //情報修正
230
+
231
+ int a = 0;
232
+
233
+ for (int i = 0; i < imgnum; i++)
234
+
235
+ {
236
+
237
+ a = count(i);
238
+
239
+ for (int j = 0; j < a; j++)
240
+
241
+ {
242
+
243
+ /*ここです*/if (imgdata_box[i][j][0]+imgdata_box[i][j][2]>imgdata_size[1])
244
+
245
+ {
246
+
247
+
248
+
249
+ }
250
+
251
+ }
252
+
253
+ }
254
+
255
+
256
+
257
+ return 0;
258
+
259
+ }
260
+
261
+
262
+
263
+ int main()
264
+
265
+ {
266
+
267
+ road();
268
+
269
+ analysis();
270
+
271
+ trimming();
272
+
273
+
274
+
275
+ return 0;
276
+
277
+ }
278
+
279
+
280
+
281
+ ```