1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41 
42 #ifndef _CV_VM_H_
43 #define _CV_VM_H_
44 
45 /*----------------------- Internal ViewMorphing Functions ------------------------------*/
46 
47 /*======================================================================================*/
48 
49 typedef struct CvMatrix4
50 {
51     float m[4][4];
52 }
53 CvMatrix4;
54 
55 
56 /* Scanline section. Find coordinates by fundamental matrix */
57 
58 /* Epsilon and real zero */
59 #define EPSILON             1.e-4
60 //#define REAL_ZERO(x)        ( (x) < EPSILON && (x) > -EPSILON)
61 #define REAL_ZERO(x) ( (x) < 1e-8 && (x) > -1e-8)
62 
63 #define SIGN(x)				( (x)<0 ? -1:((x)>0?1:0 ) )
64 
65 CvStatus  icvMakeScanlinesLengths( int*        scanlines,
66                                     int         numlines,
67                                     int*        lens);
68 
69 /*=============================== PreWarp section ======================================*/
70 
71 CV_INLINE int icvGetColor(uchar* valueRGB);
72 
73 CvStatus  icvFindRunsInOneImage(
74                                 int     numLines,       /* number of scanlines		*/
75                                 uchar*  prewarp,        /* prewarp image 			*/
76                                 int*    line_lens,      /* line lengths in pixels	*/
77                                 int*    runs,           /* result runs				*/
78                                 int*    num_runs);
79 
80 /*================================ Morphing section ====================================*/
81 
82 CvStatus  icvMorphEpilines8uC3(    uchar*  first_pix, /* raster epiline from the first image       */
83                                     uchar*  second_pix, /* raster epiline from the second image      */
84                                     uchar*  dst_pix,    /* raster epiline from the destination image */
85                                                         /* (it's an output parameter)                */
86                                     float   alpha,      /* relative position of camera               */
87                                     int*    first,      /* first sequence of runs                    */
88                                     int     first_runs, /* it's length                               */
89                                     int*    second,     /* second sequence of runs                   */
90                                     int     second_runs,
91                                     int*    first_corr, /* correspond information for the 1st seq    */
92                                     int*    second_corr,
93                                     int     dst_len);   /* correspond information for the 2nd seq    */
94 
95 /*========================== Dynamic correspond section ================================*/
96 
97 CvStatus  icvDynamicCorrespond(   int*  first,         /* first sequence of runs           */
98                                                          /* s0|w0|s1|w1|...|s(n-1)|w(n-1)|sn */
99                                     int   first_runs,    /* number of runs                   */
100                                     int*  second,        /* second sequence of runs          */
101                                     int   second_runs,
102                                     int*  first_corr,    /* s0'|e0'|s1'|e1'|...              */
103                                     int*  second_corr );
104 
105 /*============================= PostWarp Functions =====================================*/
106 
107 CvStatus  icvFetchLine8uC3R(
108                                 uchar*   src,  int   src_step,
109                                 uchar*   dst,  int*  dst_num,
110                                 CvSize  src_size,
111                                 CvPoint start,
112                                 CvPoint end );
113 
114 CvStatus  icvDrawLine8uC3R(
115                                 uchar*   src,  int  src_num,
116                                 uchar*   dst,  int  dst_step,
117                                 CvSize  dst_size,
118                                 CvPoint start,
119                                 CvPoint end );
120 
121 
122 /*============================== Fundamental Matrix Functions ==========================*/
123 CvStatus  icvPoint7(  int*        points1,
124                         int*        points2,
125                         double*     F,
126                         int*        amount
127                         );
128 
129 CvStatus  icvCubic(      double a2, double a1,
130                             double a0, double* squares );
131 
132 double icvDet( double* M );
133 double   icvMinor( double* M, int x, int y );
134 
135 int
136 icvGaussMxN( double *A, double *B, int M, int N, double **solutions );
137 
138 CvStatus
139 icvGetCoef( double *f1, double *f2, double *a2, double *a1, double *a0 );
140 
141 /*================================= Scanlines Functions ================================*/
142 
143 CvStatus  icvGetCoefficient(  CvMatrix3*     matrix,
144                                 CvSize         imgSize,
145                                 int*            scanlines_1,
146                                 int*            scanlines_2,
147                                 int*            numlines);
148 
149 CvStatus  icvGetCoefficientDefault(   CvMatrix3*     matrix,
150                                         CvSize         imgSize,
151                                         int*            scanlines_1,
152                                         int*            scanlines_2,
153                                         int*            numlines);
154 
155 CvStatus  icvGetCoefficientStereo(    CvMatrix3*     matrix,
156                                         CvSize         imgSize,
157                                         float*          l_epipole,
158                                         float*          r_epipole,
159                                         int*            scanlines_1,
160                                         int*            scanlines_2,
161                                         int*            numlines
162                                     );
163 
164 CvStatus  icvGetCoefficientOrto(  CvMatrix3*     matrix,
165                                     CvSize         imgSize,
166                                     int*            scanlines_1,
167                                     int*            scanlines_2,
168                                     int*            numlines);
169 
170 
171 CvStatus  icvGetCrossEpilineFrame(    CvSize     imgSize,
172                                         float*      epiline,
173                                         int*        x1,
174                                         int*        y1,
175                                         int*        x2,
176                                         int*        y2
177                                     );
178 
179 CvStatus  icvBuildScanlineLeftStereo(
180                                         CvSize         imgSize,
181                                         CvMatrix3*     matrix,
182                                         float*          l_epipole,
183                                         float*          l_angle,
184                                         float           l_radius,
185                                         int*            scanlines_1,
186                                         int*            scanlines_2,
187                                         int*            numlines);
188 
189 CvStatus  icvBuildScanlineRightStereo(
190                                         CvSize         imgSize,
191                                         CvMatrix3*     matrix,
192                                         float*          r_epipole,
193                                         float*          r_angle,
194                                         float           r_radius,
195                                         int*            scanlines_1,
196                                         int*            scanlines_2,
197                                         int*            numlines);
198 
199 CvStatus  icvGetStartEnd1(
200                                     CvMatrix3*     matrix,
201                                     CvSize         imgSize,
202                                     float*          l_start_end,
203                                     float*          r_start_end );
204 
205 CvStatus  icvGetStartEnd2(
206                                     CvMatrix3*     matrix,
207                                     CvSize         imgSize,
208                                     float*          l_start_end,
209                                     float*          r_start_end );
210 
211 CvStatus  icvGetStartEnd3(
212                                     CvMatrix3*     matrix,
213                                     CvSize         imgSize,
214                                     float*          l_start_end,
215                                     float*          r_start_end );
216 
217 CvStatus  icvGetStartEnd4(
218                                     CvMatrix3*     matrix,
219                                     CvSize         imgSize,
220                                     float*          l_start_end,
221                                     float*          r_start_end );
222 
223 CvStatus  icvBuildScanlineLeft(
224                                     CvMatrix3*     matrix,
225                                     CvSize         imgSize,
226                                     int*            scanlines_1,
227                                     int*            scanlines_2,
228                                     float*          l_start_end,
229                                     int*            numlines
230                                     );
231 
232 CvStatus  icvBuildScanlineRight(
233                                     CvMatrix3*     matrix,
234                                     CvSize         imgSize,
235                                     int*            scanlines_1,
236                                     int*            scanlines_2,
237                                     float*          r_start_end,
238                                     int*            numlines
239                                     );
240 
241 
242 /*=================================== LMedS Functions ==================================*/
243 CvStatus  icvLMedS7(
244                         int*            points1,
245                         int*            points2,
246                         CvMatrix3*     matrix);
247 
248 
249 CvStatus  icvLMedS(   int*    points1,
250                         int*    points2,
251                         int     numPoints,
252                         CvMatrix3* fundamentalMatrix );
253 
254 
255 /*
256 CvStatus  icvFindFundamentalMatrix(
257                                     int*            points1,
258                                     int*            points2,
259                                     int             numpoints,
260                                     int             method,
261                                     CvMatrix3*      matrix);
262 */
263 void   icvChoose7(	int*    ml,     int* mr,
264 					    int     num,	int* ml7,
265 					    int*   mr7 );
266 
267 double icvMedian(	int* ml, int* mr,
268 				    int num, double* F );
269 
270 int icvBoltingPoints( int* ml,	    int* mr,
271 					    int num,        double* F,
272 					    double Mj,      int* *new_ml,
273 					    int* *new_mr,   int* new_num);
274 
275 CvStatus  icvPoints8( int* ml, int* mr,
276                         int num, double* F );
277 
278 CvStatus  icvRank2Constraint( double* F );
279 
280 CvStatus  icvSort( double* array, int length );
281 
282 double icvAnalyticPoints8(	double* A,
283 											int num, double* F );
284 
285 int icvSingularValueDecomposition(	int		M,
286 										int		N,
287 										double*	A,
288 										double*	W,
289 										int		get_U,
290 										double*	U,
291 										int		get_V,
292 										double*	V
293 												 );
294 
295 
296 /*======================================================================================*/
297 #endif/*_CV_VM_H_*/
298 
299