-
Notifications
You must be signed in to change notification settings - Fork 0
/
testFunctions.cc
1853 lines (1571 loc) · 98.4 KB
/
testFunctions.cc
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "testFunctions.h"
/*
void estimatedDisparityTest(const cv::Mat& lookup_table, const cv::Mat& XYZd_data, const std::vector<TotalDerivatives>& derivative_vector, const int& index_row, const int& index_col, const int sampl_fact)
{
float step = float(1.f / sampl_fact);
cv::Mat estimation_matrix_1 = cv::Mat(sampl_fact + 1, sampl_fact + 1, CV_32F);
cv::Mat estimation_matrix_2 = cv::Mat(sampl_fact + 1, sampl_fact + 1, CV_32F);
cv::Mat estimation_matrix_3 = cv::Mat(sampl_fact + 1, sampl_fact + 1, CV_32F);
cv::Mat estimation_matrix_4 = cv::Mat(sampl_fact + 1, sampl_fact + 1, CV_32F);
const int TL = lookup_table.at<int>(index_row, index_col);
const int TR = lookup_table.at<int>(index_row, index_col + 1);
const int BL = lookup_table.at<int>(index_row + 1, index_col);
const int BR = lookup_table.at<int>(index_row + 1, index_col + 1);
float ii = 0;
for (float i = 0; i < estimation_matrix_1.rows; i++)
{
float jj = 0;
for (float j = 0; j < estimation_matrix_1.cols; j++)
{
cv::Vec4f est_1 = fromBigMat(TL, XYZd_data) + jj * derivative_vector[TL].der_left + ii * derivative_vector[TL].der_top;
cv::Vec4f est_2 = fromBigMat(TR, XYZd_data) + jj * derivative_vector[TR].der_right + ii * derivative_vector[TR].der_top;
cv::Vec4f est_3 = fromBigMat(BL, XYZd_data) + jj * derivative_vector[BL].der_left + ii * derivative_vector[BL].der_bot;
cv::Vec4f est_4 = fromBigMat(BR, XYZd_data) + jj * derivative_vector[BR].der_right + ii * derivative_vector[BR].der_bot;
estimation_matrix_1.at<float>(i, j) = est_1[3];
estimation_matrix_2.at<float>(i, j) = est_2[3];
estimation_matrix_3.at<float>(i, j) = est_3[3];
estimation_matrix_4.at<float>(i, j) = est_4[3];
jj += step;
}
ii += step;
}
std::cout << "TL estimations" << std::endl;
std::cout << estimation_matrix_1 << std::endl;
std::cout << "TR estimations" << std::endl;
std::cout << estimation_matrix_2 << std::endl;
std::cout << "BL estimations" << std::endl;
std::cout << estimation_matrix_3 << std::endl;
std::cout << "BR estimations" << std::endl;
std::cout << estimation_matrix_4 << std::endl;
}
void guessedDisparityTest(int image_row, int image_col, const cv::Mat& ground_truth, const cv::Mat& guessed_disparity, int& sampl_factor, int& gap)
{
int x_pos = (image_col / gap) * sampl_factor;
int y_pos = (image_row / gap) * sampl_factor;
cv::Rect estimations_patch = cv::Rect(x_pos, y_pos, sampl_factor + 1, sampl_factor + 1);
cv::Rect real_patch = cv::Rect(image_col, image_row, gap, gap);
cv::Mat roi_estimation = guessed_disparity(estimations_patch);
cv::Mat roi_ground_truth = ground_truth(real_patch);
cv::resize(roi_ground_truth, roi_ground_truth, roi_ground_truth.size()/5);
std::cout << " Estimated disparities" << std::endl;
std::cout << roi_estimation << std::endl;
std::cout << " Exact disparities" << std::endl;
std::cout << roi_ground_truth << std::endl;
}
void getMinimumCost(const cv::Mat& cost_cube, const std::vector<float>& disparity_levels, cv::Mat& input_disparity)
{
int channels = cost_cube.channels();
std::vector<int> temp_z_elements_vec(channels);
for (int i = 0; i < cost_cube.rows; i++)
{
for (int j = 0; j < cost_cube.cols; j++)
{
for (int ch = 0; ch < channels; ch++)
{
temp_z_elements_vec[ch] = cost_cube.ptr<float>(i)[channels * j + ch];
}
int disparity_index = std::min_element(temp_z_elements_vec.begin(), temp_z_elements_vec.end()) - temp_z_elements_vec.begin();
input_disparity.at<float>(i, j) = disparity_levels[disparity_index];
//std::cout << input_disparity.at<float>(i, j) << std::endl;
}
}
}
void sgmTest(const cv::Mat& lookupTable, const cv::Mat& xyd_data, const cv::Mat& XYZ_data, const cv::Mat& left_image, const cv::Mat& right_image, const int& gap, const int& lookup_r, const int& lookup_c, std::string& path_test_matrices)
{
std::vector<cv::Vec2i> pixel_positions_left_vector(4);
std::vector<float> disparity_levels_vector(4);
cv::Mat patch_cost_cube = cv::Mat(gap + 1, gap + 1, CV_32FC(4));
EstimationParameters estimation_parameters;
int window_size = estimation_parameters.setWindowSize();
float edge_threshold = estimation_parameters.setDispThreshold();
// Corners of the window
const int TL = lookupTable.at<int>(lookup_r, lookup_c);
const int TR = lookupTable.at<int>(lookup_r, lookup_c + 1);
const int BL = lookupTable.at<int>(lookup_r + 1, lookup_c);
const int BR = lookupTable.at<int>(lookup_r + 1, lookup_c + 1);
pixel_positions_left_vector = GetLeftPixelPositions(TL, TR, BL, BR, xyd_data, pixel_positions_left_vector);
disparity_levels_vector = GetDisparityLevels(TL, TR, BL, BR, xyd_data, disparity_levels_vector);
patch_cost_cube = getSGMCostCube(pixel_positions_left_vector, disparity_levels_vector, left_image, right_image, window_size, gap, patch_cost_cube);
std::cout << " | " << " TL disp " << disparity_levels_vector[0] << " | " <<
" TR disp " << disparity_levels_vector[1] << " | " <<
" BL disp " << disparity_levels_vector[2] << " | " <<
" BR disp " << disparity_levels_vector[3] << " | " << std::endl;
cv::Mat ch1, ch2, ch3, ch4;
std::vector<cv::Mat> channels(patch_cost_cube.channels());
cv::Mat disparity_output = cv::Mat(patch_cost_cube.size(), CV_32F, cv::Scalar(0));
EdgeDirection edg = EdgeDirection::undefined;
if (findEdge_deriv(TL, TR, BL, BR, XYZ_data, edg, edge_threshold) == false)
{
cv::split(patch_cost_cube, channels);
ch1 = channels[0];
ch2 = channels[1];
ch3 = channels[2];
ch4 = channels[3];
io::writeMatrixToFile(ch1, path_test_matrices + "channel 1_N.txt");
io::writeMatrixToFile(ch2, path_test_matrices + "channel 2_N.txt");
io::writeMatrixToFile(ch3, path_test_matrices + "channel 3_N.txt");
io::writeMatrixToFile(ch4, path_test_matrices + "channel 4_N.txt");
getMinimumCost(patch_cost_cube, disparity_levels_vector, disparity_output);
io::writeMatrixToFile(disparity_output, path_test_matrices + "disparity_N.txt");
}
else
{
float P1 = 5;
float P2 = 40;
if (edg == EdgeDirection::vertical)
{
cv::Mat direction_cost_cube_0 = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
cv::Mat direction_cost_cube_2 = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
cv::Mat total_cost_cube = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
// Direction 0 (FROM LEFT)
// Calculate the cost for the left borders pixel
aggregationCostDirection0(patch_cost_cube, direction_cost_cube_0, P1, P2);
// Direction 2 (FROM RIGHT)
// Calculate the cost for the right borders pixel
aggregationCostDirection2(patch_cost_cube, direction_cost_cube_2, P1, P2);
total_cost_cube = direction_cost_cube_0 + direction_cost_cube_2;
cv::split(total_cost_cube, channels);
ch1 = channels[0];
ch2 = channels[1];
ch3 = channels[2];
ch4 = channels[3];
io::writeMatrixToFile(ch1, path_test_matrices + "channel 1_V.txt");
io::writeMatrixToFile(ch2, path_test_matrices + "channel 2_V.txt");
io::writeMatrixToFile(ch3, path_test_matrices + "channel 3_V.txt");
io::writeMatrixToFile(ch4, path_test_matrices + "channel 4_V.txt");
getMinimumCost(total_cost_cube, disparity_levels_vector, disparity_output);
io::writeMatrixToFile(disparity_output, path_test_matrices + "disparity_V.txt");
}
else if (edg == EdgeDirection::horizontal)
{
cv::Mat direction_cost_cube_1 = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
cv::Mat direction_cost_cube_3 = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
cv::Mat total_cost_cube = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
// Direction 1 (FROM TOP)
// Calculate the cost for the top borders pixel
aggregationCostDirection1(patch_cost_cube, direction_cost_cube_1, P1, P2);
// Direction 3 (FROM BOT)
// Calculate the cost for the bottom borders pixel
aggregationCostDirection3(patch_cost_cube, direction_cost_cube_3, P1, P2);
total_cost_cube = direction_cost_cube_1 + direction_cost_cube_3;
cv::split(total_cost_cube, channels);
ch1 = channels[0];
ch2 = channels[1];
ch3 = channels[2];
ch4 = channels[3];
io::writeMatrixToFile(ch1, path_test_matrices + "channel 1_H.txt");
io::writeMatrixToFile(ch2, path_test_matrices + "channel 2_H.txt");
io::writeMatrixToFile(ch3, path_test_matrices + "channel 3_H.txt");
io::writeMatrixToFile(ch4, path_test_matrices + "channel 4_H.txt");
getMinimumCost(total_cost_cube, disparity_levels_vector, disparity_output);
io::writeMatrixToFile(disparity_output, path_test_matrices + "disparity_H.txt");
}
else if (edg == EdgeDirection::undefined)
{
cv::Mat direction_cost_cube_0 = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
cv::Mat direction_cost_cube_2 = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
cv::Mat direction_cost_cube_1 = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
cv::Mat direction_cost_cube_3 = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
cv::Mat total_cost_cube = cv::Mat(patch_cost_cube.size(), patch_cost_cube.type(), cv::Scalar(0));
// Direction 0 (FROM LEFT)
// Calculate the cost for the left borders pixel
aggregationCostDirection0(patch_cost_cube, direction_cost_cube_0, P1, P2);
// Direction 1 (FROM TOP)
// Calculate the cost for the top borders pixel
aggregationCostDirection1(patch_cost_cube, direction_cost_cube_1, P1, P2);
// Direction 2 (FROM RIGHT)
// Calculate the cost for the right borders pixel
aggregationCostDirection2(patch_cost_cube, direction_cost_cube_2, P1, P2);
// Direction 3 (FROM BOT)
// Calculate the cost for the bottom borders pixel
aggregationCostDirection3(patch_cost_cube, direction_cost_cube_3, P1, P2);
total_cost_cube = direction_cost_cube_0 + direction_cost_cube_1 + direction_cost_cube_2 + direction_cost_cube_3;
cv::split(total_cost_cube, channels);
ch1 = channels[0];
ch2 = channels[1];
ch3 = channels[2];
ch4 = channels[3];
io::writeMatrixToFile(ch1, path_test_matrices + "channel 1_U.txt");
io::writeMatrixToFile(ch2, path_test_matrices + "channel 2_U.txt");
io::writeMatrixToFile(ch3, path_test_matrices + "channel 3_U.txt");
io::writeMatrixToFile(ch4, path_test_matrices + "channel 4_U.txt");
getMinimumCost(total_cost_cube, disparity_levels_vector, disparity_output);
io::writeMatrixToFile(disparity_output, path_test_matrices + "disparity_U.txt");
}
}
}
*/
void RealGridOperationsTesting::setEstimationParameters(const cv::Mat& camera_matrix_left_, const cv::Mat& camera_matrix_right_, const float& baseline_, const int& sampling_factor_)
{
camera_matrix_left = camera_matrix_left_;
camera_matrix_right = camera_matrix_right_;
sampling_factor = sampling_factor_;
step = static_cast<float>(1.f / sampling_factor_);
baseline = baseline_;
CostPenalties cost_penalties;
P0 = cost_penalties.P_0;
P1 = cost_penalties.P_1;
P2 = cost_penalties.P_2;
P3 = cost_penalties.P_3;
P4 = cost_penalties.P_4;
P1_sgm = cost_penalties.P1_sgm;
P2_sgm = cost_penalties.P2_sgm;
}
void RealGridOperationsTesting::setNecessaryVectors(const std::vector<GridSquare>& gridSquaresVector_, const std::vector<ObservationData>& observationsVector_, const std::vector<CompleteValuesDerivatives>& internalCompleteDerivativesVector_, const std::vector<CompleteValuesDerivatives>& esternalCompleteDerivativesVector_)
{
gridSquaresVector = gridSquaresVector_;
observationsVector = observationsVector_;
internalCompleteDerivativesVector = internalCompleteDerivativesVector_;
esternalCompleteDerivativesVector = esternalCompleteDerivativesVector_;
}
void RealGridOperationsTesting::initilizeEstimationMatrices()
{
int cols_est = (sampling_factor + 1) * (sampling_factor + 1);
int rows_est = gridSquaresVector.size();
cv::Size matrix_size_est = cv::Size(cols_est, rows_est);
estimated_Disparity = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_X = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Y = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Z = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Disparity_no_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_X_no_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Y_no_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Z_no_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Disparity_strong_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_X_strong_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Y_strong_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Z_strong_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Disparity_soft_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_X_soft_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Y_soft_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
estimated_Z_soft_edge = cv::Mat(matrix_size_est, CV_32F, cv::Scalar::all(0));
int rows_guess = estimated_Disparity_no_edge.rows * estimated_Disparity_no_edge.cols;
cv::Size matrix_size_guess = cv::Size(1, rows_guess);
guessed_Disparity = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_X = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Y = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Z = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Disparity_no_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_X_no_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Y_no_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Z_no_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Disparity_strong_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_X_strong_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Y_strong_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Z_strong_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Disparity_soft_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_X_soft_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Y_soft_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
guessed_Z_soft_edge = cv::Mat(matrix_size_guess, CV_32F, cv::Scalar::all(0));
}
void RealGridOperationsTesting::setEstimations(const cv::Mat& image_left, const cv::Mat& image_right)
{
/*
int cols = (sampling_factor + 1) * (sampling_factor + 1);
int rows = gridSquaresVector.size();
cv::Size matrix_size = cv::Size(cols, rows);
estimated_Disparity = cv::Mat(matrix_size, CV_32F, cv::Scalar::all(0));
estimated_X = cv::Mat(matrix_size, CV_32F, cv::Scalar::all(0));
estimated_Y = cv::Mat(matrix_size, CV_32F, cv::Scalar::all(0));
estimated_Z = cv::Mat(matrix_size, CV_32F, cv::Scalar::all(0));
*/
MatrixLimits matrix_limits;
left_image_limits = matrix_limits.defineMatrixLimits(0, image_left.rows, 0, image_left.cols).t();
right_image_limits = matrix_limits.defineMatrixLimits(0, image_right.rows, 0, image_right.cols).t();
float no_edges_step = 0.f;
int size = 4;
std::vector<ObservationData> no_edge_estimations(size, ObservationData());
std::vector<ObservationData> strong_edge_estimations(size, ObservationData());
std::vector<ObservationData> soft_edge_estimations(size, ObservationData());
int best_index = 0;
// SubPatch indeces
int TL = 0;
int TR = 0;
int BL = 0;
int BR = 0;
int d = 0;
bool is_strong_edge = false;
bool is_soft_edge = false;
for (size_t i = 0; i < gridSquaresVector.size(); i++)
{
TL = gridSquaresVector[i].top_left_index;
TR = gridSquaresVector[i].top_right_index;
BL = gridSquaresVector[i].bottom_left_index;
BR = gridSquaresVector[i].bottom_right_index;
d = 0;
EdgeShape edg = EdgeShape::undefined;
is_strong_edge = findStrongEdges(TL, TR, BL, BR, edg);
is_soft_edge = findSoftEdges(TL, TR, BL, BR, edg);
if (is_soft_edge == false)
{
// Check if there could be strong edges
if (is_strong_edge == false)
{
// No edges
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
// Fast bilinear interpolation using the corner values
// Is it better to have the mean value among the corners or do only one estimation using only one corner ?
noEdgesEstimations(TL, TR, BL, BR, ii, jj, no_edge_estimations);
estimated_Disparity.at<float>(i, d) = final_estimastion_no_edge_internal_deriv.disp;
estimated_Z.at<float>(i, d) = final_estimastion_no_edge_internal_deriv.Z_mt;
estimated_X.at<float>(i, d) = final_estimastion_no_edge_internal_deriv.X_mt;
estimated_Y.at<float>(i, d) = final_estimastion_no_edge_internal_deriv.Y_mt;
estimated_Disparity_no_edge.at<float>(i, d) = final_estimastion_no_edge_internal_deriv.disp;
estimated_Z_no_edge.at<float>(i, d) = final_estimastion_no_edge_internal_deriv.Z_mt;
estimated_X_no_edge.at<float>(i, d) = final_estimastion_no_edge_internal_deriv.X_mt;
estimated_Y_no_edge.at<float>(i, d) = final_estimastion_no_edge_internal_deriv.Y_mt;
d++;
}
}
}
else
{
// Strong edge case
std::fill(raw_differences.begin(), raw_differences.end(), FLT_MAX);
if (edg == EdgeShape::pure_vertical)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
strongEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, strong_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P1 * ii + P2 * jj;
raw_differences[1] = raw_differences[1] + P1 * ii + P2 * (1 - jj);
raw_differences[2] = raw_differences[2] + P1 * (1 - ii) + P2 * jj;
raw_differences[3] = raw_differences[3] + P1 * (1 - ii) + P2 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = strong_edge_estimations[best_index].disp;
estimated_X_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
//std::cout << "Estimated point at TL: " << estimated_X_strong_edge.at<float>(i, d) << std::endl;
//std::cout << "Real point at TL: " << strong_edge_estimations[best_index].X_mt << std::endl;
estimated_Y_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
//std::cout << estimated_Y_strong_edge.at<float>(i, d) << std::endl;
estimated_Z_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::pure_horizontal)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
strongEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, strong_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P2 * ii + P1 * jj;
raw_differences[1] = raw_differences[1] + P2 * ii + P1 * (1 - jj);
raw_differences[2] = raw_differences[2] + P2 * (1 - ii) + P1 * jj;
raw_differences[3] = raw_differences[3] + P2 * (1 - ii) + P1 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = strong_edge_estimations[best_index].disp;
estimated_X_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::diagonal_top_left)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
strongEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, strong_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
// The few bigger penalty should go on the different edge or on the other three edges ?
raw_differences[0] = raw_differences[0] + P4 * ii + P4 * jj;
raw_differences[1] = raw_differences[1] + P3 * ii + P3 * (1 - jj);
raw_differences[2] = raw_differences[2] + P3 * (1 - ii) + P3 * jj;
raw_differences[3] = raw_differences[3] + P3 * (1 - ii) + P3 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = strong_edge_estimations[best_index].disp;
estimated_X_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::diagonal_top_right)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
strongEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, strong_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P3 * ii + P3 * jj;
raw_differences[1] = raw_differences[1] + P4 * ii + P4 * (1 - jj);
raw_differences[2] = raw_differences[2] + P3 * (1 - ii) + P3 * jj;
raw_differences[3] = raw_differences[3] + P3 * (1 - ii) + P3 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = strong_edge_estimations[best_index].disp;
estimated_X_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::diagonal_bottom_left)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
strongEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, strong_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P3 * ii + P3 * jj;
raw_differences[1] = raw_differences[1] + P3 * ii + P3 * (1 - jj);
raw_differences[2] = raw_differences[2] + P4 * (1 - ii) + P4 * jj;
raw_differences[3] = raw_differences[3] + P3 * (1 - ii) + P3 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = strong_edge_estimations[best_index].disp;
estimated_X_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::diagonal_bottom_right)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
strongEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, strong_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P3 * ii + P3 * jj;
raw_differences[1] = raw_differences[1] + P3 * ii + P3 * (1 - jj);
raw_differences[2] = raw_differences[2] + P3 * (1 - ii) + P3 * jj;
raw_differences[3] = raw_differences[3] + P4 * (1 - ii) + P4 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = strong_edge_estimations[best_index].disp;
estimated_X_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].disp;
d++;
}
}
}
else
{
// Unknown type of edge --> maybe use a big penalty for all the estimations
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
strongEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, strong_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P0 * ii + P0 * jj;
raw_differences[1] = raw_differences[1] + P0 * ii + P0 * (1 - jj);
raw_differences[2] = raw_differences[2] + P0 * (1 - ii) + P0 * jj;
raw_differences[3] = raw_differences[3] + P0 * (1 - ii) + P0 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = strong_edge_estimations[best_index].disp;
estimated_X_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_strong_edge.at<float>(i, d) = (strong_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * strong_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].Z_mt;
estimated_Disparity_strong_edge.at<float>(i, d) = strong_edge_estimations[best_index].disp;
d++;
}
}
}
}
}
else
{
// Soft edges case
if (edg == EdgeShape::pure_vertical)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
softEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, soft_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P1 * ii + P2 * jj;
raw_differences[1] = raw_differences[1] + P1 * ii + P2 * (1 - jj);
raw_differences[2] = raw_differences[2] + P1 * (1 - ii) + P2 * jj;
raw_differences[3] = raw_differences[3] + P1 * (1 - ii) + P2 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = soft_edge_estimations[best_index].disp;
estimated_X_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::pure_horizontal)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
softEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, soft_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P2 * ii + P1 * jj;
raw_differences[1] = raw_differences[1] + P2 * ii + P1 * (1 - jj);
raw_differences[2] = raw_differences[2] + P2 * (1 - ii) + P1 * jj;
raw_differences[3] = raw_differences[3] + P2 * (1 - ii) + P1 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = soft_edge_estimations[best_index].disp;
estimated_X_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::diagonal_top_left)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
softEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, soft_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P4 * ii + P4 * jj;
raw_differences[1] = raw_differences[1] + P3 * ii + P3 * (1 - jj);
raw_differences[2] = raw_differences[2] + P3 * (1 - ii) + P3 * jj;
raw_differences[3] = raw_differences[3] + P3 * (1 - ii) + P3 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = soft_edge_estimations[best_index].disp;
estimated_X_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::diagonal_top_right)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
softEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, soft_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P3 * ii + P3 * jj;
raw_differences[1] = raw_differences[1] + P4 * ii + P4 * (1 - jj);
raw_differences[2] = raw_differences[2] + P3 * (1 - ii) + P3 * jj;
raw_differences[3] = raw_differences[3] + P3 * (1 - ii) + P3 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = soft_edge_estimations[best_index].disp;
estimated_X_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::diagonal_bottom_left)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
softEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, soft_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P3 * ii + P3 * jj;
raw_differences[1] = raw_differences[1] + P3 * ii + P3 * (1 - jj);
raw_differences[2] = raw_differences[2] + P4 * (1 - ii) + P4 * jj;
raw_differences[3] = raw_differences[3] + P3 * (1 - ii) + P3 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = soft_edge_estimations[best_index].disp;
estimated_X_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].disp;
d++;
}
}
}
else if (edg == EdgeShape::diagonal_bottom_right)
{
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
softEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, soft_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P3 * ii + P3 * jj;
raw_differences[1] = raw_differences[1] + P3 * ii + P3 * (1 - jj);
raw_differences[2] = raw_differences[2] + P3 * (1 - ii) + P3 * jj;
raw_differences[3] = raw_differences[3] + P4 * (1 - ii) + P4 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = soft_edge_estimations[best_index].disp;
estimated_X_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].disp;
d++;
}
}
}
else
{
// Undefined edge case
for (float ii = 0.f; ii <= 1.f; ii += step)
{
for (float jj = 0.f; jj <= 1.f; jj += step)
{
softEdgesEstimations(TL, TR, BL, BR, ii, jj, image_left, image_right, soft_edge_estimations);
// Is there the need to add penalties? Maybe yes in order to be really sure about the results
// Then with the penalty it is possible to enhance the different edge shape cases
raw_differences[0] = raw_differences[0] + P0 * ii + P0 * jj;
raw_differences[1] = raw_differences[1] + P0 * ii + P0 * (1 - jj);
raw_differences[2] = raw_differences[2] + P0 * (1 - ii) + P0 * jj;
raw_differences[3] = raw_differences[3] + P0 * (1 - ii) + P0 * (1 - jj);
best_index = std::min_element(raw_differences.begin(), raw_differences.end()) - raw_differences.begin();
estimated_X.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity.at<float>(i, d) = soft_edge_estimations[best_index].disp;
estimated_X_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].x_px - camera_matrix_left.at<float>(0, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(0, 0);
estimated_Y_soft_edge.at<float>(i, d) = (soft_edge_estimations[best_index].y_px - camera_matrix_left.at<float>(1, 2)) * soft_edge_estimations[best_index].Z_mt / camera_matrix_left.at<float>(1, 1);
estimated_Z_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].Z_mt;
estimated_Disparity_soft_edge.at<float>(i, d) = soft_edge_estimations[best_index].disp;
d++;
}
}
}
}
}
}
void RealGridOperationsTesting::setGuesses()
{
int TL_indx{ 0 };
int TR_indx{ 0 };
int BL_indx{ 0 };
int BR_indx{ 0 };
/*
// Matrix initialization
int rows = estimated_Disparity.rows * estimated_Disparity.cols;
cv::Size matrix_size = cv::Size(1, rows);
guessed_Disparity = cv::Mat(matrix_size, CV_32F, cv::Scalar::all(0));
guessed_X = cv::Mat(matrix_size, CV_32F, cv::Scalar::all(0));
guessed_Y = cv::Mat(matrix_size, CV_32F, cv::Scalar::all(0));
guessed_Z = cv::Mat(matrix_size, CV_32F, cv::Scalar::all(0));
*/
int r = 0;
for (size_t i = 0; i < estimated_Disparity.rows; i++)
{
for (size_t j = 0; j < estimated_Disparity.cols; j++)
{
guessed_Disparity.at<float>(r, 0) = estimated_Disparity.at<float>(i, j);
guessed_X.at<float>(r, 0) = estimated_X.at<float>(i, j);
guessed_Y.at<float>(r, 0) = estimated_Y.at<float>(i, j);
guessed_Z.at<float>(r, 0) = estimated_Z.at<float>(i, j);
guessed_Disparity_no_edge.at<float>(r, 0) = estimated_Disparity_no_edge.at<float>(i, j);
guessed_X_no_edge.at<float>(r, 0) = estimated_X_no_edge.at<float>(i, j);
guessed_Y_no_edge.at<float>(r, 0) = estimated_Y_no_edge.at<float>(i, j);
guessed_Z_no_edge.at<float>(r, 0) = estimated_Z_no_edge.at<float>(i, j);
guessed_Disparity_strong_edge.at<float>(r, 0) = estimated_Disparity_strong_edge.at<float>(i, j);
guessed_X_strong_edge.at<float>(r, 0) = estimated_X_strong_edge.at<float>(i, j);
guessed_Y_strong_edge.at<float>(r, 0) = estimated_Y_strong_edge.at<float>(i, j);
guessed_Z_strong_edge.at<float>(r, 0) = estimated_Z_strong_edge.at<float>(i, j);
guessed_Disparity_soft_edge.at<float>(r, 0) = estimated_Disparity_soft_edge.at<float>(i, j);
guessed_X_soft_edge.at<float>(r, 0) = estimated_X_soft_edge.at<float>(i, j);
guessed_Y_soft_edge.at<float>(r, 0) = estimated_Y_soft_edge.at<float>(i, j);
guessed_Z_soft_edge.at<float>(r, 0) = estimated_Z_soft_edge.at<float>(i, j);
if (j == 0)
{
TL_indx = gridSquaresVector[i].top_left_index;
guessed_Disparity.at<float>(r, 0) = observationsVector[TL_indx].disp;
guessed_X.at<float>(r, 0) = observationsVector[TL_indx].X_mt;
guessed_Y.at<float>(r, 0) = observationsVector[TL_indx].Y_mt;
guessed_Z.at<float>(r, 0) = observationsVector[TL_indx].Z_mt;
guessed_Disparity_no_edge.at<float>(r, 0) = observationsVector[TL_indx].disp;
guessed_X_no_edge.at<float>(r, 0) = observationsVector[TL_indx].X_mt;
guessed_Y_no_edge.at<float>(r, 0) = observationsVector[TL_indx].Y_mt;
guessed_Z_no_edge.at<float>(r, 0) = observationsVector[TL_indx].Z_mt;
guessed_Disparity_strong_edge.at<float>(r, 0) = observationsVector[TL_indx].disp;
guessed_X_strong_edge.at<float>(r, 0) = observationsVector[TL_indx].X_mt;
guessed_Y_strong_edge.at<float>(r, 0) = observationsVector[TL_indx].Y_mt;
guessed_Z_strong_edge.at<float>(r, 0) = observationsVector[TL_indx].Z_mt;
guessed_Disparity_soft_edge.at<float>(r, 0) = observationsVector[TL_indx].disp;
guessed_X_soft_edge.at<float>(r, 0) = observationsVector[TL_indx].X_mt;
guessed_Y_soft_edge.at<float>(r, 0) = observationsVector[TL_indx].Y_mt;
guessed_Z_soft_edge.at<float>(r, 0) = observationsVector[TL_indx].Z_mt;
}
else if (j == sampling_factor)
{
TR_indx = gridSquaresVector[i].top_right_index;
guessed_Disparity.at<float>(r, 0) = observationsVector[TR_indx].disp;
guessed_X.at<float>(r, 0) = observationsVector[TR_indx].X_mt;
guessed_Y.at<float>(r, 0) = observationsVector[TR_indx].Y_mt;
guessed_Z.at<float>(r, 0) = observationsVector[TR_indx].Z_mt;
guessed_Disparity_no_edge.at<float>(r, 0) = observationsVector[TR_indx].disp;
guessed_X_no_edge.at<float>(r, 0) = observationsVector[TR_indx].X_mt;
guessed_Y_no_edge.at<float>(r, 0) = observationsVector[TR_indx].Y_mt;
guessed_Z_no_edge.at<float>(r, 0) = observationsVector[TR_indx].Z_mt;
guessed_Disparity_strong_edge.at<float>(r, 0) = observationsVector[TR_indx].disp;
guessed_X_strong_edge.at<float>(r, 0) = observationsVector[TR_indx].X_mt;
guessed_Y_strong_edge.at<float>(r, 0) = observationsVector[TR_indx].Y_mt;
guessed_Z_strong_edge.at<float>(r, 0) = observationsVector[TR_indx].Z_mt;
guessed_Disparity_soft_edge.at<float>(r, 0) = observationsVector[TR_indx].disp;
guessed_X_soft_edge.at<float>(r, 0) = observationsVector[TR_indx].X_mt;
guessed_Y_soft_edge.at<float>(r, 0) = observationsVector[TR_indx].Y_mt;
guessed_Z_soft_edge.at<float>(r, 0) = observationsVector[TR_indx].Z_mt;
}
else if (j == float(estimated_Disparity.cols - 1 - sampling_factor))
{
BL_indx = gridSquaresVector[i].bottom_left_index;
guessed_Disparity.at<float>(r, 0) = observationsVector[BL_indx].disp;
guessed_X.at<float>(r, 0) = observationsVector[BL_indx].X_mt;
guessed_Y.at<float>(r, 0) = observationsVector[BL_indx].Y_mt;
guessed_Z.at<float>(r, 0) = observationsVector[BL_indx].Z_mt;
guessed_Disparity_no_edge.at<float>(r, 0) = observationsVector[BL_indx].disp;
guessed_X_no_edge.at<float>(r, 0) = observationsVector[BL_indx].X_mt;
guessed_Y_no_edge.at<float>(r, 0) = observationsVector[BL_indx].Y_mt;
guessed_Z_no_edge.at<float>(r, 0) = observationsVector[BL_indx].Z_mt;
guessed_Disparity_strong_edge.at<float>(r, 0) = observationsVector[BL_indx].disp;
guessed_X_strong_edge.at<float>(r, 0) = observationsVector[BL_indx].X_mt;
guessed_Y_strong_edge.at<float>(r, 0) = observationsVector[BL_indx].Y_mt;
guessed_Z_strong_edge.at<float>(r, 0) = observationsVector[BL_indx].Z_mt;
guessed_Disparity_soft_edge.at<float>(r, 0) = observationsVector[BL_indx].disp;
guessed_X_soft_edge.at<float>(r, 0) = observationsVector[BL_indx].X_mt;
guessed_Y_soft_edge.at<float>(r, 0) = observationsVector[BL_indx].Y_mt;
guessed_Z_soft_edge.at<float>(r, 0) = observationsVector[BL_indx].Z_mt;
}
else if (j == float(estimated_Disparity.cols - 1))
{
BR_indx = gridSquaresVector[i].bottom_right_index;
guessed_Disparity.at<float>(r, 0) = observationsVector[BR_indx].disp;
guessed_X.at<float>(r, 0) = observationsVector[BR_indx].X_mt;
guessed_Y.at<float>(r, 0) = observationsVector[BR_indx].Y_mt;
guessed_Z.at<float>(r, 0) = observationsVector[BR_indx].Z_mt;
guessed_Disparity_no_edge.at<float>(r, 0) = observationsVector[BR_indx].disp;
guessed_X_no_edge.at<float>(r, 0) = observationsVector[BR_indx].X_mt;
guessed_Y_no_edge.at<float>(r, 0) = observationsVector[BR_indx].Y_mt;
guessed_Z_no_edge.at<float>(r, 0) = observationsVector[BR_indx].Z_mt;
guessed_Disparity_strong_edge.at<float>(r, 0) = observationsVector[BR_indx].disp;
guessed_X_strong_edge.at<float>(r, 0) = observationsVector[BR_indx].X_mt;
guessed_Y_strong_edge.at<float>(r, 0) = observationsVector[BR_indx].Y_mt;
guessed_Z_strong_edge.at<float>(r, 0) = observationsVector[BR_indx].Z_mt;
guessed_Disparity_soft_edge.at<float>(r, 0) = observationsVector[BR_indx].disp;
guessed_X_soft_edge.at<float>(r, 0) = observationsVector[BR_indx].X_mt;
guessed_Y_soft_edge.at<float>(r, 0) = observationsVector[BR_indx].Y_mt;
guessed_Z_soft_edge.at<float>(r, 0) = observationsVector[BR_indx].Z_mt;
}
r++;
}
}
}
void RealGridOperationsTesting::setSGMCostCubes(const std::vector<cv::Mat>& SGMCostCubesVector_)
{
SGMCostCubesVector = SGMCostCubesVector_;
int SGMVectors_size = avg_square_size_4eye * avg_square_size_4eye * SGMCostCubesVector.size();
SGMEstimatedDisparity.resize(SGMVectors_size);
SGMEstimated_X.resize(SGMVectors_size);
SGMEstimated_Y.resize(SGMVectors_size);
SGMEstimated_Z.resize(SGMVectors_size);
SGMEstimated_x_px.resize(SGMVectors_size);
SGMEstimated_y_px.resize(SGMVectors_size);
}
void RealGridOperationsTesting::setSGMBasedEstimations(const cv::Mat& image_left, const cv::Mat& image_right)
{
// Disparity levels vector
std::vector<float> patch_disparity_values(4, 0.f);