Browse Source

Removed old file.

Joel Janai 2 years ago
parent
commit
94a81b6d03
1 changed files with 0 additions and 698 deletions
  1. 0 698
      accumulate.cpp

+ 0 - 698
accumulate.cpp

@@ -1,698 +0,0 @@
1
-/*
2
- * accumulate.cpp
3
- *
4
- *  Created on: Mar 7, 2016
5
- *      Author: Janai
6
- */
7
-
8
-#include <iostream>
9
-#include <fstream>
10
-#include <stdio.h>
11
-#include <string>
12
-#include <cmath>
13
-#include <omp.h>
14
-#include <random>
15
-
16
-#include <opencv2/core.hpp>
17
-#include <opencv2/highgui.hpp>
18
-#include <opencv2/imgproc.hpp>
19
-
20
-#include <boost/filesystem.hpp>
21
-
22
-#include "epic.h"
23
-#include "image.h"
24
-#include "io.h"
25
-#include "variational_mt.h"
26
-#include "utils/edge_detector.h"
27
-#include "utils/utils.h"
28
-
29
-#include "../multi_frame_flow/multi_frame_optical_flow.h"
30
-#include "../multi_frame_flow/utils/parameter_list.h"
31
-
32
-#include "../libs/middlebury_devkit/cpp/colorcode.h"
33
-#include "../libs/middlebury_devkit/cpp/flowIO.h"
34
-
35
-using namespace std;
36
-using namespace cv;
37
-
38
-void setDefaultVariational(ParameterList& params) {
39
-    // general
40
-    params.insert("verbose", "0", true);
41
-    params.insert("threads", "1", true);
42
-
43
-//    params.insert("format", "img_%04d.tif", true);
44
-
45
-    params.insert("stats", "0", true);
46
-    params.insert("S", "2", true);
47
-
48
-    params.insert("scale", "1.0f", true);
49
-
50
-    params.insert("dataterm", "1");
51
-    params.insert("smoothing", "1");
52
-
53
-    params.insert("epic_alpha", "1.0f");
54
-    params.insert("epic_gamma", "0.72f", true);
55
-    params.insert("epic_delta", "0.0f", true);
56
-
57
-    params.insert("layers", "1", true);
58
-    params.insert("p_scale", "0.9f", true);;
59
-
60
-    params.insert("niter_alter", "1", true);
61
-    params.insert("niter_outer", "5", true);
62
-    params.insert("thres_outer", "1e-5", true);
63
-    params.insert("niter_inner", "1", true);
64
-    params.insert("thres_inner", "1e-5", true);
65
-    params.insert("niter_solver", "30", true);
66
-    params.insert("sor_omega", "1.9f", true);
67
-
68
-    params.insert("robust_color", "1", true);
69
-    params.insert("robust_color_eps", "0.001", true);
70
-    params.insert("robust_color_truncation", "0.5", true);
71
-    params.insert("robust_reg", "1", true);
72
-    params.insert("robust_reg_eps", "0.001", true);
73
-    params.insert("robust_reg_truncation", "0.5", true);
74
-
75
-    params.insert("gradient_sigmoid", "5.0f", true);
76
-}
77
-
78
-int main(int argc, char **argv) {
79
-	/*
80
-	 *  getting config file location
81
-	 */
82
-#define isarg(key)  !strcmp(a,key)
83
-	string file;
84
-	string input_path = "";
85
-	string output_path = "";
86
-	if (argc > 1) {
87
-		file = string(argv[1]);
88
-
89
-		if(boost::filesystem::exists(file)) {
90
-			printf("using parameters %s\n", file.c_str());
91
-		} else {
92
-			cerr << "usage: ./accumulate [cfg-file] -input_path [path] -output_path [path] {optional:Frames}" << endl;
93
-			return -1;
94
-		}
95
-
96
-		int selected_jet = -1;
97
-		int current_arg = 1;
98
-		while(current_arg < argc ){
99
-			const char* a = argv[current_arg++];
100
-			if(a[0] != '-') {
101
-				continue;
102
-			}
103
-
104
-			if( isarg("-h") || isarg("-help") )
105
-				cerr << "usage: ./accumulate [cfg-file] -input_path [path] -output_path [path] {optional:Frames}" << endl;
106
-			else if( isarg("-input_path") )
107
-				input_path = string(argv[current_arg++]);
108
-			else if( isarg("-output_path") )
109
-				output_path = string(argv[current_arg++]);
110
-			else{
111
-				fprintf(stderr, "unknown argument %s", a);
112
-				cerr << "usage: ./accumulate [cfg-file] -input_path [path] -output_path [path] {optional:Frames}" << endl;
113
-				exit(1);
114
-			}
115
-		}
116
-	} else {
117
-		cerr << "usage: ./accumulate [cfg-file] -input_path [path] -output_path [path] {optional:Frames}" << endl;
118
-		return -1;
119
-	}
120
-
121
-	/*
122
-	 *  read in parameters and print config
123
-	 */
124
-	ParameterList params;
125
-
126
-	params.read(file);
127
-	string path = file.substr(0, file.find_last_of('/'));
128
-
129
-	bool sintel = params.parameter<bool>("sintel", "0");
130
-
131
-	// add input path and output path
132
-	params.setParameter("flow_file", input_path + params.parameter("flow_file"));
133
-	for(int i = 0; i < params.file_list.size(); i++)
134
-		params.file_list[i] = input_path + params.file_list[i];
135
-	for(int i = 0; i < params.file_gt_list.size(); i++)
136
-		params.file_gt_list[i] = input_path + params.file_gt_list[i];
137
-	params.output = path + "/";
138
-
139
-	/*
140
-	 * decompose sequence in subsets and adjust number of frames if necessary
141
-	 */
142
-	uint32_t Jets = params.Jets;
143
-
144
-	if (!params.exists("S") || params.parameter<int>("S") < 2)
145
-		params.setParameter<int>("S", 2);
146
-
147
-	int steps = params.parameter<int>("S") - 1;
148
-
149
-	if(Jets == 0) {
150
-		Jets = floor(params.F / steps);
151
-		params.Jets = Jets;
152
-	}
153
-
154
-
155
-//	int batch_size = floor((1.0f * params.parameter<int>("max_fps")) / (params.parameter<int>("ref_fps")));
156
-	int batch_size = floor((1.0f * params.parameter<int>("max_fps")) / (params.parameter<int>("jet_fps")));
157
-//	int batches = floor((1.0f * params.Jets) * batch_size);
158
-	Jets = floor(batch_size / steps);
159
-	int batches = params.parameter<int>("batches", "1");
160
-
161
-	int skip = floor((1.0f * params.parameter<int>("max_fps")) / (params.parameter<int>("jet_fps")));
162
-	if(params.exists("frames")) {
163
-		// decompose sequence in batches
164
-		skip = ceil(1.0f * batch_size / (params.parameter<int>("frames") - 1.0));			// with ceil we will estimate too far by fractions
165
-		Jets = floor(1.0f * Jets / skip);
166
-	}
167
-
168
-	// iterate over experiments
169
-	for(uint32_t exp = 0; exp < params.experiments(); exp++) {
170
-		ParameterList exp_params;
171
-
172
-		exp_params = ParameterList(params);
173
-		params.nextExp();
174
-
175
-		// get scaling factor
176
-		double scale = params.parameter<float>("scale", "1.0");
177
-
178
-		string flow_format = exp_params.parameter<string>("flow_format", "frame_%i");
179
-
180
-		// create folder for accumulated batches
181
-		stringstream acc_folder;
182
-		acc_folder << exp_params.output << "accumulation/";
183
-		boost::filesystem::create_directories(acc_folder.str());
184
-		boost::filesystem::create_directories(acc_folder.str() + "gt_occlusions/");          // accumulate folder
185
-
186
-		exp_params.insert("accumulation", acc_folder.str() , true);
187
-		exp_params.Jets = batches;
188
-		stringstream news;
189
-		news << batch_size*steps + 1;
190
-		exp_params.setParameter("S", news.str());
191
-
192
-		exp_params.print();
193
-
194
-		ofstream infos;
195
-		infos.open((acc_folder.str() + "config.cfg").c_str());
196
-		infos << "# SlowFlow variational estimation\n";
197
-		infos << exp_params;
198
-		infos.close();
199
-
200
-		uint32_t num_sources = params.file_list.size();
201
-
202
-		for (uint32_t source = 0; source < num_sources; source++) {
203
-			for(int b = 0; b < batches; b++) {
204
-				if(b > 0)
205
-					exp_params.sequence_start_list[source] += Jets * skip * steps;
206
-
207
-				// read in sequence, forward and backward flow, and segmentation
208
-				Mat* gt = NULL;  	 	 // plus reference frame
209
-				Mat* gt_occlusions = NULL;
210
-
211
-				Mat *forward_flow = new Mat[Jets];
212
-				Mat *backward_flow = new Mat[Jets];
213
-
214
-				/*
215
-				 * ################### read in ground truth ###################
216
-				 */
217
-				if(exp_params.file_gt.size() > 0) {
218
-					gt = new Mat[batch_size];
219
-					for (uint32_t f = 0; f < (batch_size); f++) {
220
-						char gtF[200];
221
-
222
-						if(!sintel)
223
-							sprintf(gtF, exp_params.file_gt_list[source].c_str(), exp_params.sequence_start_list[source] + f);
224
-						else {
225
-							int sintel_frame = exp_params.sequence_start_list[source] / 1000;
226
-							int hfr_frame = f + (exp_params.sequence_start_list[source] % 1000);
227
-
228
-							while(hfr_frame < 0) {
229
-								sintel_frame--;
230
-								hfr_frame = 42 + hfr_frame;
231
-							}
232
-							while(hfr_frame > 41) {
233
-								sintel_frame++;
234
-								hfr_frame = hfr_frame - 42;
235
-							}
236
-
237
-							sprintf(gtF, exp_params.file_gt_list[source].c_str(), sintel_frame, hfr_frame);
238
-						}
239
-
240
-						if (access(gtF, F_OK) == -1) {
241
-							continue;
242
-							cerr << "Error reading "<< gtF << "!" << endl;
243
-						}
244
-						cout << "Reading "<< gtF << "!" << endl;
245
-
246
-						gt[f] = readGTMiddlebury(gtF);
247
-
248
-						// rescale gt flow
249
-						resize(gt[f], gt[f], Size(0, 0), scale, scale, INTER_LINEAR);
250
-						gt[f] = scale * gt[f];
251
-					}
252
-				}
253
-
254
-				/*
255
-				 * ################### read in ground truth occlusions ###################
256
-				 */
257
-				if(exp_params.occlusions_list.size() > 0) {
258
-					gt_occlusions = new Mat[batch_size];
259
-					for (u_int32_t f = 0; f < (uint32_t) (batch_size); f++) {
260
-						char oocF[500];
261
-
262
-						if(!sintel)
263
-							sprintf(oocF, exp_params.occlusions_list[source].c_str(), exp_params.sequence_start_list[source] + f);
264
-						else {
265
-							int sintel_frame = exp_params.sequence_start_list[source] / 1000;
266
-							int hfr_frame = f + (exp_params.sequence_start_list[source] % 1000);
267
-
268
-							while(hfr_frame < 0) {
269
-								sintel_frame--;
270
-								hfr_frame = 42 + hfr_frame;
271
-							}
272
-							while(hfr_frame > 41) {
273
-								sintel_frame++;
274
-								hfr_frame = hfr_frame - 42;
275
-							}
276
-
277
-							sprintf(oocF, exp_params.occlusions_list[source].c_str(), sintel_frame, hfr_frame);
278
-						}
279
-
280
-						// read file only if already processed by first experiment
281
-						if(access( oocF, F_OK ) != -1) {
282
-							cout << "Reading "<< oocF << "!" << endl;
283
-
284
-							gt_occlusions[f] = imread(string(oocF));
285
-
286
-							resize(gt_occlusions[f], gt_occlusions[f], Size(0, 0), scale, scale, INTER_CUBIC);
287
-
288
-							memset(oocF, 0, 500);
289
-							sprintf(oocF, "%s/gt_occlusions/occ_%05i.png", acc_folder.str().c_str(), exp_params.sequence_start + f);
290
-							// read file only if already processed by first experiment
291
-							if(access( oocF, F_OK ) == -1) {
292
-								// write flow and flow image to file
293
-								imwrite(oocF, gt_occlusions[f]);
294
-							}
295
-
296
-							if(gt_occlusions[f].channels() > 1)
297
-								cvtColor(gt_occlusions[f], gt_occlusions[f], CV_BGR2GRAY);
298
-							gt_occlusions[f].convertTo(gt_occlusions[f], CV_8UC1);
299
-						} else {
300
-							cerr << "Error reading "<< oocF << "!" << endl;
301
-						}
302
-					}
303
-				}
304
-
305
-
306
-				char source_str[1024];
307
-				if(params.name_list.size() > 1)
308
-					sprintf(source_str, "%s%02i_", params.name_list[source].c_str(), params.id(source));
309
-				else
310
-					source_str[0] = '\0';
311
-
312
-				/*
313
-				 * ################### read in flow fields ###################
314
-				 */
315
-				for (uint32_t f = 0; f < Jets; f++) {
316
-					char fFlowF[200];
317
-					char bFlowF[200];
318
-
319
-	//				if (exp_params.exists("flow_file")) {
320
-	//					if(!sintel) {
321
-	//						sprintf(fFlowF, (exp_params.parameter("flow_file") + ".flo").c_str(), exp_params.sequence_start_list[source] + f * steps);
322
-	//						sprintf(bFlowF, (exp_params.parameter("flow_file") + "_back.flo").c_str(), exp_params.sequence_start_list[source] + f * steps + steps);
323
-	//					} else {
324
-	//						sprintf(fFlowF, (exp_params.parameter("flow_file") + ".flo").c_str(), exp_params.sequence_start_list[source] + f * steps, 0);
325
-	//						sprintf(bFlowF, (exp_params.parameter("flow_file") + "_back.flo").c_str(), exp_params.sequence_start_list[source] + f * steps + steps, 0);
326
-	//					}
327
-	//				} else {
328
-	//					sprintf(fFlowF, "%sframe_%i.flo", exp_params.output.c_str(), (exp_params.sequence_start_list[source] + f * steps));
329
-	//					sprintf(bFlowF, "%sframe_%i_back.flo", exp_params.output.c_str(), (exp_params.sequence_start_list[source] + f * steps + steps));
330
-	//				}
331
-					string hfr = "";
332
-					if (boost::filesystem::exists( exp_params.output + "hfr/" ))
333
-						hfr = "hfr/";
334
-
335
-					sprintf(fFlowF, ("%s%s" + flow_format + ".flo").c_str(), (exp_params.output + hfr).c_str(), source_str, (exp_params.sequence_start_list[source] + f * steps * skip));
336
-					if (exp_params.parameter<bool>("wrong_backward", "0"))
337
-						sprintf(bFlowF, ("%s%s" + flow_format + "_back.flo").c_str(), (exp_params.output + hfr).c_str(), source_str,
338
-								(exp_params.sequence_start_list[source] + f * steps * skip));
339
-					else
340
-						sprintf(bFlowF, ("%s%s" + flow_format + "_back.flo").c_str(), (exp_params.output + hfr).c_str(), source_str,
341
-								(exp_params.sequence_start_list[source] + f * steps * skip + steps * skip));
342
-
343
-					if (!boost::filesystem::exists(fFlowF)) {
344
-						cerr << fFlowF << " does not exist!" << endl;
345
-						return -1;
346
-					}
347
-					if (!boost::filesystem::exists(bFlowF)) {
348
-						cerr << bFlowF << " does not exist!" << endl;
349
-						return -1;
350
-					}
351
-
352
-					cout << "Reading " << fFlowF <<  endl;
353
-					cout << "Reading " << bFlowF <<  endl;
354
-
355
-					forward_flow[f] = readGTMiddlebury(fFlowF);
356
-					backward_flow[f] = readGTMiddlebury(bFlowF);
357
-
358
-					// crop images
359
-					if(exp_params.center.x > 0) {
360
-						// NOTE: ROWRANGE IS INDUCING ERRORS IN ACCUMULATION!!!!!!
361
-						forward_flow[f] = crop(forward_flow[f], exp_params.center, exp_params.extent);
362
-						backward_flow[f] = crop(backward_flow[f], exp_params.center, exp_params.extent);
363
-					}
364
-				}
365
-				Mat lfr_occlusions = Mat::zeros(forward_flow[0].rows, forward_flow[0].cols, CV_8UC1);
366
-				if(gt != NULL && gt_occlusions != NULL) lfr_occlusions = fuseOcclusions(gt, gt_occlusions, 0, Jets);
367
-
368
-				// accumulate ground truth flow
369
-				Mat fconf, bconf;
370
-				Mat* acc_flow = new Mat[Jets];
371
-//				accumulateFlow(acc_flow,  &forward_flow[b * Jets], lfr_occlusions, Jets);
372
-				accumulateConsistentBatches(acc_flow, forward_flow, backward_flow, fconf, bconf, NULL, Jets, params.parameter<double>("acc_consistency_threshold_slope"), 0, params.parameter<bool>("acc_discard_inconsistent", "1"), 0);
373
-
374
-				/*
375
-				 *  ########################################### Refine flow ###########################################
376
-				 */
377
-
378
-//				if(exp_params.parameter<bool>("refine", "1")) {
379
-//					int width = acc_flow->cols;
380
-//					int height = acc_flow->rows;
381
-//
382
-//					ParameterList refine_params(exp_params);
383
-//					setDefaultVariational(refine_params);
384
-//					refine_params.F = 2;
385
-//					refine_params.Jets = 1;
386
-//					refine_params.insert("S", "2", true);
387
-//					refine_params.verbose = "1000";
388
-//					refine_params.insert("layers", "1", true);
389
-//					refine_params.insert("method", "forward", true);
390
-//					refine_params.insert("niter_alter", "1", true);
391
-//					refine_params.insert("niter_outer", "5", true);
392
-//					refine_params.insert("occlusion_reasoning", "0", true);
393
-//					refine_params.insert("framerate_reasoning", "0", true);
394
-//					refine_params.insert("rho_0", "1", true);
395
-//					refine_params.insert("omega_0", "0", true);
396
-//
397
-//					color_image_t** im = new color_image_t*[3];
398
-//					im[0] = color_image_new(width, height);
399
-//					im[1] = color_image_new(width, height);
400
-//					im[2] = color_image_new(width, height);
401
-//
402
-
403
-//					/*
404
-//					 * ################### read in image sequence ###################
405
-//					 */
406
-//					for (uint32_t f = 0; f < 2; f++) {
407
-//						char img_file[1024];
408
-//						if (!sintel) {
409
-//							sprintf(img_file, (sequence_path + format).c_str(), thread_params.sequence_start_list[source] + f * Jets * steps * skip);
410
-//						} else {
411
-//							int sintel_frame = thread_params.sequence_start_list[source] / 1000;
412
-//							int hfr_frame = f * steps * skip + (thread_params.sequence_start_list[source] % 1000);
413
-//
414
-//							while (hfr_frame < 0) {
415
-//								sintel_frame--;
416
-//								hfr_frame = 42 + hfr_frame;
417
-//							}
418
-//							while (hfr_frame > 41) {
419
-//								sintel_frame++;
420
-//								hfr_frame = hfr_frame - 42;
421
-//							}
422
-//
423
-//							sprintf(img_file, (sequence_path + format).c_str(), sintel_frame, hfr_frame);
424
-//						}
425
-//						cout << "Reading " << img_file << "..." << endl;
426
-//
427
-//						sequence[f] = imread(string(img_file), CV_LOAD_IMAGE_UNCHANGED);         // load images
428
-//
429
-//						float norm = 1;
430
-//						if (sequence[f].type() == 2 || sequence[f].type() == 18)
431
-//							norm = 1.0f / 255;		// for 16 bit images
432
-//
433
-//						// convert to floating point
434
-//						sequence[f].convertTo(sequence[f], CV_32FC(sequence[f].channels()));
435
-//
436
-//						/*
437
-//						 * DEMOSAICING
438
-//						 */
439
-//						if (thread_params.exists("raw") && thread_params.parameter<bool>("raw")) {
440
-//							Mat tmp = sequence[f].clone();
441
-//							color_image_t* tmp_in = color_image_new(sequence[f].cols, sequence[f].rows);
442
-//							color_image_t* tmp_out = color_image_new(sequence[f].cols, sequence[f].rows);
443
-//
444
-//							switch (thread_params.parameter<int>("raw_demosaicing", "0")) {
445
-//								case 0: // use bilinear demosaicing
446
-//									sequence[f] = Mat::zeros(tmp.rows, tmp.cols, CV_32FC3);
447
-//									//						bayer2rgb(tmp, sequence[f], green_start, blue_start); 	// red green
448
-//									bayer2rgbGR(tmp, sequence[f], red_loc[0], red_loc[1]); // red green
449
-//									break;
450
-//
451
-//								case 1:	// use hamilton adams demosaicing
452
-//									mat2colorImg<float>(sequence[f], tmp_in);
453
-//
454
-//									HamiltonAdamsDemosaic(tmp_out->c1, tmp_in->c1, tmp_in->width, tmp_in->height, red_loc[0], red_loc[1]); // Hamilton-Adams implemented by Pascal Getreuer
455
-//
456
-//									sequence[f] = Mat::zeros(sequence[f].rows, sequence[f].cols, CV_32FC3);
457
-//									colorImg2colorMat<Vec3f>(tmp_out, sequence[f]);
458
-//									break;
459
-//
460
-//								case 2: // use opencv demosaicing
461
-//									tmp.convertTo(tmp, CV_8UC1);
462
-//									sequence[f] = Mat::zeros(tmp.rows, tmp.cols, CV_8UC3);
463
-//
464
-//									int code = CV_BayerBG2RGB;
465
-//									if (red_loc[1] == 0) // y
466
-//										if (red_loc[0] == 0) // x
467
-//											code = CV_BayerBG2RGB;
468
-//										else
469
-//											code = CV_BayerGB2RGB;
470
-//									else if (red_loc[0] == 0) // x
471
-//										code = CV_BayerGR2RGB;
472
-//									else
473
-//										code = CV_BayerRG2RGB;
474
-//
475
-//									cv::cvtColor(tmp, sequence[f], code); // components from second row, second column !!!!!!!!!!!!!!!!!
476
-//									sequence[f].convertTo(sequence[f], CV_32FC(sequence[f].channels()));
477
-//									break;
478
-//							}
479
-//
480
-//							color_image_delete(tmp_in);
481
-//							color_image_delete(tmp_out);
482
-//						} else {
483
-//							// covert to RGB
484
-//							cv::cvtColor(sequence[f], sequence[f], CV_BGR2RGB);
485
-//						}
486
-//
487
-//						/*
488
-//						 * COLOR CORRECTION
489
-//						 */
490
-//						vector<Mat> channels;
491
-//						split(sequence[f], channels);
492
-//						float mid_val = (0.5 * 255.0 / norm);
493
-//						channels[0] = contrast * (channels[0] + red_balance + brightness - mid_val) + mid_val;
494
-//						channels[1] = contrast * (channels[1] + green_balance + brightness - mid_val) + mid_val;
495
-//						channels[2] = contrast * (channels[2] + blue_balance + brightness - mid_val) + mid_val;
496
-//						merge(channels, sequence[f]);
497
-//
498
-//						if (thread_params.parameter<bool>("grayscale", "0"))
499
-//							cvtColor(sequence[f], sequence[f], CV_RGB2GRAY);
500
-//
501
-//						// use only a part of the images
502
-//						if (thread_params.extent.x > 0 || thread_params.extent.y > 0) {
503
-//							sequence[f] = sequence[f].rowRange(Range(thread_params.center.y - thread_params.extent.y / 2, thread_params.center.y + thread_params.extent.y / 2));
504
-//							sequence[f] = sequence[f].colRange(Range(thread_params.center.x - thread_params.extent.x / 2, thread_params.center.x + thread_params.extent.x / 2));
505
-//						}
506
-//
507
-//						// rescale image with gaussian blur to avoid anti-aliasing
508
-//						double img_scale = thread_params.parameter<double>("scale", "1.0");
509
-//						if (img_scale != 1) {
510
-//							GaussianBlur(sequence[f], sequence[f], Size(0, 0), 1 / sqrt(2 * img_scale), 1 / sqrt(2 * img_scale), BORDER_REPLICATE);
511
-//							resize(sequence[f], sequence[f], Size(0, 0), img_scale, img_scale, INTER_LINEAR);
512
-//						}
513
-//
514
-//						// print to file
515
-//						char file[1024];
516
-//						sprintf(file, (acc_folder.str() + "sequence/frame_%s%i.png").c_str(), source_str, thread_params.sequence_start_list[source] - steps * skip + f * skip);
517
-//
518
-//						Mat output_img;
519
-//						if (thread_params.parameter<bool>("16bit", "0")) {
520
-//							sequence[f].convertTo(output_img, CV_16UC(sequence[f].channels()));
521
-//						} else {
522
-//							sequence[f].convertTo(output_img, CV_8UC(sequence[f].channels()), norm);
523
-//						}
524
-//
525
-//						if (thread_params.parameter<bool>("grayscale", "0"))
526
-//							cv::cvtColor(output_img, output_img, CV_GRAY2BGR);	// OpenCV uses BGR
527
-//						else
528
-//							cv::cvtColor(output_img, output_img, CV_RGB2BGR);	// OpenCV uses BGR
529
-//
530
-//						if (thread_params.verbosity(WRITE_FILES)) {
531
-//							imwrite(file, output_img, compression_params);
532
-//						}
533
-//
534
-//						data[f] = color_image_new(sequence[f].cols, sequence[f].rows);
535
-//						if (thread_params.parameter<bool>("grayscale", "0"))
536
-//							mat2colorImg<float>(sequence[f], data[f]);
537
-//						else
538
-//							colorMat2colorImg<Vec3f>(sequence[f], data[f]);
539
-//
540
-//						if (thread_params.verbosity(VER_IN_GT) && (int) f < show_frames) {
541
-//							if (source == show_frames_source) {
542
-//								stringstream ftitle;
543
-//								ftitle << "Frame " << source;
544
-//								namedWindow(ftitle.str());               // Create a window for display.
545
-//								imshow(ftitle.str(), output_img);
546
-//
547
-//								// set the callback function for pixel selection
548
-//								int* cbparams = new int[2];
549
-//								cbparams[0] = f;
550
-//								cbparams[1] = source;
551
-//								setMouseCallback(ftitle.str(), CallBackFunc, cbparams);
552
-//
553
-//								waitKey(0);
554
-//							}
555
-//						}
556
-//					}
557
-//
558
-//					// normalize data terms
559
-//					normalize(data, Jets + 1, thread_params);
560
-//
561
-//					// rescale image with gaussian blur to avoid anti-aliasing
562
-//					double rescale = 1.0f * width / width;
563
-//					Mat tmp_1 = sequence[0].clone(),
564
-//						tmp_2 = sequence[Jets].clone();
565
-//					if (rescale != 1) {
566
-//						GaussianBlur(tmp_1, tmp_1, Size(0, 0), 1 / sqrt(2 * rescale), 1 / sqrt(2 * rescale), BORDER_REPLICATE);
567
-//						GaussianBlur(tmp_2, tmp_2, Size(0, 0), 1 / sqrt(2 * rescale), 1 / sqrt(2 * rescale), BORDER_REPLICATE);
568
-//					}
569
-//					resize(tmp_1, tmp_1, Size(width, height), 0, 0, INTER_LINEAR);
570
-//					resize(tmp_2, tmp_2, Size(width, height), 0, 0, INTER_LINEAR);
571
-//					if (thread_params.parameter<bool>("grayscale", "0")) {
572
-//						mat2colorImg<float>(tmp_2, im[0]);// assumes backward frame for symmetric option
573
-//						mat2colorImg<float>(tmp_1, im[1]);
574
-//						mat2colorImg<float>(tmp_2, im[2]);
575
-//					} else {
576
-//						colorMat2colorImg<Vec3f>(tmp_2, im[0]);// assumes backward frame for symmetric option
577
-//						colorMat2colorImg<Vec3f>(tmp_1, im[1]);
578
-//						colorMat2colorImg<Vec3f>(tmp_2, im[2]);
579
-//					}
580
-//
581
-//					normalize(im, 3, refine_params);
582
-//
583
-//					image_t *wx = image_new(im[0]->width, im[0]->height), *wy = image_new(im[0]->width, im[0]->height);
584
-//					vector<Mat> vu;
585
-//					split(flow[0][Jets - 1], vu);
586
-//					mat2img<double>(vu[1], wx);
587
-//					mat2img<double>(vu[0], wy);
588
-//
589
-////						bool change = true;
590
-////						while(change) {
591
-////							for(int i=0 ; i<wx->height ; i++){
592
-////								for( int j=0 ; j<wx->width ; j++){
593
-////									change = false;
594
-////
595
-////									if(wx->data[i*wx->stride+j] > UNKNOWN_FLOW_THRESH) {
596
-////										wx->data[i*wx->stride+j] = 0;
597
-////										int count = 0;
598
-////										if(wx->data[(i+1)*wx->stride+j] < UNKNOWN_FLOW_THRESH) {
599
-////											wx->data[i*wx->stride+j] += wx->data[(i+1)*wx->stride+j];
600
-////											count++;
601
-////										}
602
-////										if(wx->data[(i-1)*wx->stride+j] < UNKNOWN_FLOW_THRESH) {
603
-////											wx->data[i*wx->stride+j] += wx->data[(i-1)*wx->stride+j];
604
-////											count++;
605
-////										}
606
-////										if(wx->data[i*wx->stride+(j+1)] < UNKNOWN_FLOW_THRESH) {
607
-////											wx->data[i*wx->stride+j] += wx->data[i*wx->stride+(j+1)];
608
-////											count++;
609
-////										}
610
-////										if(wx->data[i*wx->stride+(j-1)] < UNKNOWN_FLOW_THRESH) {
611
-////											wx->data[i*wx->stride+j] += wx->data[i*wx->stride+(j-1)];
612
-////											count++;
613
-////										}
614
-////
615
-////										wx->data[i*wx->stride+j] = wx->data[i*wx->stride+j] / count;
616
-////										change = true;
617
-////									}
618
-////
619
-////									if(wy->data[i*wy->stride+j] > UNKNOWN_FLOW_THRESH) {
620
-////										wy->data[i*wy->stride+j] = 0;
621
-////										int count = 0;
622
-////										if(wy->data[(i+1)*wy->stride+j] < UNKNOWN_FLOW_THRESH) {
623
-////											wy->data[i*wy->stride+j] += wy->data[(i+1)*wy->stride+j];
624
-////											count++;
625
-////										}
626
-////										if(wy->data[(i-1)*wy->stride+j] < UNKNOWN_FLOW_THRESH) {
627
-////											wy->data[i*wy->stride+j] += wy->data[(i-1)*wy->stride+j];
628
-////											count++;
629
-////										}
630
-////										if(wy->data[i*wy->stride+(j+1)] < UNKNOWN_FLOW_THRESH) {
631
-////											wy->data[i*wy->stride+j] += wy->data[i*wy->stride+(j+1)];
632
-////											count++;
633
-////										}
634
-////										if(wy->data[i*wy->stride+(j-1)] < UNKNOWN_FLOW_THRESH) {
635
-////											wy->data[i*wy->stride+j] += wy->data[i*wy->stride+(j-1)];
636
-////											count++;
637
-////										}
638
-////
639
-////										wy->data[i*wy->stride+j] = wy->data[i*wy->stride+j] / count;
640
-////										change = true;
641
-////									}
642
-////								}
643
-////							}
644
-////						}
645
-//
646
-//					// energy minimization
647
-//				//	time(&t_start);
648
-//					Variational_MT minimzer_f;
649
-//					minimzer_f.variational(wx, wy, im, refine_params);
650
-//				//	time(&t_end);
651
-//
652
-//					img2mat<double>(wx, vu[1]);
653
-//					img2mat<double>(wy, vu[0]);
654
-//					merge(vu, flow[0][Jets - 1]);
655
-//
656
-//					color_image_delete(im[0]);
657
-//					color_image_delete(im[1]);
658
-//					color_image_delete(im[2]);
659
-//					delete[] im;
660
-//					image_delete(wx);
661
-//					image_delete(wy);
662
-//				}
663
-
664
-				// write final estimation
665
-//				stringstream flowF;
666
-//				flowF << acc_folder.str() << "/" << exp_params.name_list[source].c_str() << source  << "frame_" << exp_params.sequence_start_list[source] + steps * batch_size * b;
667
-				char flowF[200];
668
-				sprintf(flowF, ("%s/%s" + flow_format).c_str(), acc_folder.str().c_str(), source_str, (exp_params.sequence_start_list[source]));
669
-
670
-
671
-				Mat flow_img = flowColorImg(acc_flow[Jets-1], exp_params.verbosity(VER_CMD));
672
-
673
-				if (!flow_img.data) {                 // Check for invalid input
674
-					cout << "No flow for frame " << exp_params.sequence_start_list[source] << std::endl;
675
-					continue;
676
-				}
677
-
678
-				imwrite((string(flowF) + "_vis.png"), flow_img);
679
-
680
-				writeFlowMiddlebury(acc_flow[Jets-1], (string(flowF) + ".flo"));
681
-
682
-				//----------------------------------
683
-				// ########################################### final clean up ###########################################
684
-				//----------------------------------
685
-
686
-
687
-				if(gt != NULL) 				delete[] gt;
688
-				if(gt_occlusions != NULL) 	delete[] gt_occlusions;
689
-				delete[] forward_flow;
690
-				delete[] backward_flow;
691
-			}
692
-		}
693
-	}
694
-
695
-	return 0;
696
-}
697
-
698
-