1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
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.
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.
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.
46 icvMorphEpilines8uC3( uchar * first_pix, /* raster epiline from image 1 */
47 uchar * second_pix, /* raster epiline from image 2 */
48 uchar * dst_pix, /* raster epiline from dest image */
49 /* (it's an output parameter) */
50 float alpha, /* relative position of camera */
51 int *first, /* first sequence of runs */
52 int first_runs, /* it's length */
53 int *second, /* second sequence of runs */
54 int second_runs, int *first_corr, /* corr data for the 1st seq */
55 int *second_corr, /* corr data for the 2nd seq */
59 float alpha1; /* alpha - 1.0 */
60 int s, s1; /* integer variant of alpha and alpha1 ( 0 <= s,s1 <= 256 ) */
61 int curr; /* current index in run's array */
63 float begLine; /* begin of current run */
64 float endLine; /* end of current run */
66 float begCorr; /* begin of correspondence destination of run */
67 float endCorr; /* end of correspondence destination of run */
69 int begDestLine; /* begin of current destanation of run */
70 int endDestLine; /* end of current destanation of run */
77 memset( dst_pix, 0, dst_len );
78 alpha1 = (float) (1.0 - alpha);
80 s = (int) (alpha * 256);
83 /* --------------Create first line------------- */
85 begLineIndex = first[0];
86 begLine = (float) begLineIndex;
90 for( n = 0; n < first_runs; n++ )
93 begCorr = (float) first_corr[curr];
95 endCorr = (float) first_corr[curr];
97 endLineIndex = first[curr];
98 endLine = (float) endLineIndex;
100 begDestLine = (int) (alpha * begLine + alpha1 * begCorr);
101 endDestLine = (int) (alpha * endLine + alpha1 * endCorr);
103 indexImg1 = begDestLine * 3;
106 if( endDestLine != begDestLine )
107 step = (endLine - begLine) / ((float) (endDestLine - begDestLine));
109 if( begCorr != endCorr )
112 for( ; begDestLine < endDestLine; begDestLine++ )
116 begLineIndex = (int) begLine;
120 dst_pix[indexImg1] = (uchar) (((int) (first_pix[begLineIndex]) * s) >> 8);
125 dst_pix[indexImg1] = (uchar) (((int) (first_pix[begLineIndex + 1]) * s) >> 8);
130 dst_pix[indexImg1] = (uchar) (((int) (first_pix[begLineIndex + 2]) * s) >> 8);
141 for( ; begDestLine < endDestLine; begDestLine++ )
145 begLineIndex = (int) begLine;
149 dst_pix[indexImg1] = first_pix[begLineIndex];
153 dst_pix[indexImg1] = first_pix[begLineIndex + 1];
157 dst_pix[indexImg1] = first_pix[begLineIndex + 2];
166 begLineIndex = endLineIndex;
170 } /* for each runs in first line */
172 begLineIndex = second[0];
173 begLine = (float) begLineIndex;
177 /* --------------Create second line------------- */
179 for( n = 0; n < second_runs; n++ )
182 begCorr = (float) second_corr[curr];
184 endCorr = (float) second_corr[curr];
186 endLineIndex = second[curr];
187 endLine = (float) endLineIndex;
189 begDestLine = (int) (alpha1 * begLine + alpha * begCorr);
190 endDestLine = (int) (alpha1 * endLine + alpha * endCorr);
192 indexImg1 = begDestLine * 3;
195 if (endDestLine != begDestLine)
196 step = (endLine - begLine) / ((float) (endDestLine - begDestLine));
198 if( begCorr != endCorr )
201 for( ; begDestLine < endDestLine; begDestLine++ )
205 begLineIndex = (int) begLine;
210 (uchar) (dst_pix[indexImg1] +
211 (uchar) (((unsigned int) (second_pix[begLineIndex]) * s1) >> 8));
217 (uchar) (dst_pix[indexImg1] +
218 (uchar) (((unsigned int) (second_pix[begLineIndex + 1]) * s1) >>
225 (uchar) (dst_pix[indexImg1] +
226 (uchar) (((unsigned int) (second_pix[begLineIndex + 2]) * s1) >>
238 for( ; begDestLine < endDestLine; begDestLine++ )
242 begLineIndex = (int) begLine;
246 dst_pix[indexImg1] = (uchar) (dst_pix[indexImg1] + second_pix[begLineIndex]);
251 (uchar) (dst_pix[indexImg1] + second_pix[begLineIndex + 1]);
256 (uchar) (dst_pix[indexImg1] + second_pix[begLineIndex + 2]);
257 /*assert(indexImg1 < dst_len); */
266 begLineIndex = endLineIndex;
269 } /* for each runs in second line */
273 } /* icvMorphEpilines8uC3 */
276 /*======================================================================================*/
279 icvMorphEpilines8uC3Multi( int lines, /* number of lines */
280 uchar * first_pix, /* raster epilines from the first image */
281 int *first_num, /* numbers of pixel in first line */
282 uchar * second_pix, /* raster epilines from the second image */
283 int *second_num, /* numbers of pixel in second line */
284 uchar * dst_pix, /* raster epiline from the destination image */
285 /* (it's an output parameter) */
286 int *dst_num, /* numbers of pixel in output line */
287 float alpha, /* relative position of camera */
288 int *first, /* first sequence of runs */
289 int *first_runs, /* it's length */
290 int *second, /* second sequence of runs */
291 int *second_runs, int *first_corr, /* correspond information for the 1st seq */
292 int *second_corr ) /* correspond information for the 2nd seq */
296 int currFirstPix = 0;
297 //int currFirstNum = 0;
298 int currSecondPix = 0;
299 //int currSecondNum = 0;
302 //int currFirstRuns = 0;
304 //int currSecondRuns = 0;
305 int currFirstCorr = 0;
306 int currSecondCorr = 0;
319 second == 0 || second_runs == 0 || first_corr == 0 || second_corr == 0 )
320 return CV_BADFACTOR_ERR;
322 for( currLine = 0; currLine < lines; currLine++ )
325 error = icvMorphEpilines8uC3( &(first_pix[currFirstPix]),
326 &(second_pix[currSecondPix]),
327 &(dst_pix[currDstPix]),
330 first_runs[currLine],
331 &(second[currSecond]),
332 second_runs[currLine],
333 &(first_corr[currFirstCorr]),
334 &(second_corr[currSecondCorr]), dst_num[currLine] * 3 );
337 if( error != CV_NO_ERR )
340 currFirstPix += first_num[currLine] * 3;
341 currSecondPix += second_num[currLine] * 3;
342 currDstPix += dst_num[currLine] * 3;
343 currFirst += (first_runs[currLine] * 2) + 1;
344 currSecond += (second_runs[currLine] * 2) + 1;
345 currFirstCorr += first_runs[currLine] * 2;
346 currSecondCorr += second_runs[currLine] * 2;
352 } /* icvMorphEpilines8uC3Multi */
357 /*======================================================================================*/
360 cvMorphEpilinesMulti( int lines, /* number of lines */
361 uchar * first_pix, /* raster epilines from the first image */
362 int *first_num, /* numbers of pixel in first line */
363 uchar * second_pix, /* raster epilines from the second image */
364 int *second_num, /* numbers of pixel in second line */
365 uchar * dst_pix, /* raster epiline from the destination image */
366 /* (it's an output parameter) */
367 int *dst_num, /* numbers of pixel in output line */
368 float alpha, /* relative position of camera */
369 int *first, /* first sequence of runs */
370 int *first_runs, /* it's length */
371 int *second, /* second sequence of runs */
372 int *second_runs, int *first_corr, /* correspond information for the 1st seq */
373 int *second_corr /* correspond information for the 2nd seq */
376 CV_FUNCNAME( "cvMorphEpilinesMulti" );
379 IPPI_CALL( icvMorphEpilines8uC3Multi( lines, /* number of lines */
380 first_pix, /* raster epilines from the first image */
381 first_num, /* numbers of pixel in first line */
382 second_pix, /* raster epilines from the second image */
383 second_num, /* numbers of pixel in second line */
384 dst_pix, /* raster epiline from the destination image */
385 /* (it's an output parameter) */
386 dst_num, /* numbers of pixel in output line */
387 alpha, /* relative position of camera */
388 first, /* first sequence of runs */
389 first_runs, /* it's length */
390 second, /* second sequence of runs */
391 second_runs, first_corr, /* correspond information for the 1st seq */
392 second_corr /* correspond information for the 2nd seq */