-
Notifications
You must be signed in to change notification settings - Fork 2
/
rectify_compute_disp_range.c
127 lines (104 loc) · 1.78 KB
/
rectify_compute_disp_range.c
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
#include "header.h"
#include "proto.h"
void rectify_compute_disp_range(
int w,
int h,
int match_nbr,
match_struct *match_arr,
double H_l_mat[9],
double H_r_mat[9],
int *pmin_d,
int *pmax_d
)
/*
Get min and max disparity
for the left and right rectified images
Disparity d is defined as I_l(x_l)=I_r(x_r=x_l-d)
*/
{
double min_d_dbl;
double max_d_dbl;
int match_ind;
double match3_l[3];
double match3_r[3];
double x_l;
double y_l;
double x2_l;
double y2_l;
double x_r;
double y_r;
double x2_r;
double y2_r;
double d_dbl;
int d;
int min_d;
int max_d;
/*
Initialize
*/
min_d_dbl= 1.0e32;
max_d_dbl=-1.0e32;
/*
Loop on all matches
*/
for ( match_ind= 0 ; match_ind< match_nbr ; match_ind++ ) {
match3_l[0]= match_arr[match_ind].x1;
match3_l[1]= match_arr[match_ind].y1;
match3_l[2]= 1;
match3_r[0]= match_arr[match_ind].x2;
match3_r[1]= match_arr[match_ind].y2;
match3_r[2]= 1;
/*
Apply left homography to pixel in unrectified left image
*/
x_l= match3_l[0];
y_l= match3_l[1];
homography_apply(
H_l_mat,
x_l,
y_l,
&x2_l,
&y2_l
);
/*
Apply right homography to pixel in unrectified right image
*/
x_r= match3_r[0];
y_r= match3_r[1];
homography_apply(
H_r_mat,
x_r,
y_r,
&x2_r,
&y2_r
);
/*
Compute disparity
*/
d_dbl= x2_l-x2_r;
if ( d_dbl < min_d_dbl )
min_d_dbl= d_dbl;
if ( d_dbl > max_d_dbl )
max_d_dbl= d_dbl;
}
/*
Get min_d_dbl's floor
*/
d_dbl= min_d_dbl;
if ( d_dbl >= 0.0 )
d= (int)d_dbl;
else
d= (int)d_dbl-1;
min_d= d;
/*
Get max_d_dbl's ceiling
*/
d_dbl= max_d_dbl;
if ( d_dbl >= 0.0 )
d= (int)d_dbl+1;
else
d= (int)d_dbl;
max_d= d;
(*pmin_d)= min_d;
(*pmax_d)= max_d;
}