Update the changelog
[opencv] / cvaux / src / cvbgfg_common.cpp
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 //
12 // Copyright (C) 2000, Intel Corporation, all rights reserved.
13 // Third party copyrights are property of their respective owners.
14 //
15 // Redistribution and use in source and binary forms, with or without modification,
16 // are permitted provided that the following conditions are met:
17 //
18 //   * Redistribution's of source code must retain the above copyright notice,
19 //     this list of conditions and the following disclaimer.
20 //
21 //   * Redistribution's in binary form must reproduce the above copyright notice,
22 //     this list of conditions and the following disclaimer in the documentation
23 //     and/or other materials provided with the distribution.
24 //
25 //   * The name of Intel Corporation may not be used to endorse or promote products
26 //     derived from this software without specific prior written permission.
27 //
28 // This software is provided by the copyright holders and contributors "as is" and
29 // any express or implied warranties, including, but not limited to, the implied
30 // warranties of merchantability and fitness for a particular purpose are disclaimed.
31 // In no event shall the Intel Corporation or contributors be liable for any direct,
32 // indirect, incidental, special, exemplary, or consequential damages
33 // (including, but not limited to, procurement of substitute goods or services;
34 // loss of use, data, or profits; or business interruption) however caused
35 // and on any theory of liability, whether in contract, strict liability,
36 // or tort (including negligence or otherwise) arising in any way out of
37 // the use of this software, even if advised of the possibility of such damage.
38 //
39 //M*/
40
41 #include "_cvaux.h"
42
43 //  Function cvRefineForegroundMaskBySegm preforms FG post-processing based on segmentation
44 //    (all pixels of the segment will be classified as FG if majority of pixels of the region are FG).
45 // parameters:
46 //      segments - pointer to result of segmentation (for example MeanShiftSegmentation)
47 //      bg_model - pointer to CvBGStatModel structure
48 CV_IMPL void cvRefineForegroundMaskBySegm( CvSeq* segments, CvBGStatModel*  bg_model )
49 {
50         IplImage* tmp_image = cvCreateImage(cvSize(bg_model->foreground->width,bg_model->foreground->height),
51                                                         IPL_DEPTH_8U, 1);
52         for( ; segments; segments = ((CvSeq*)segments)->h_next )
53         {
54                 CvSeq seq = *segments;
55                 seq.v_next = seq.h_next = NULL;
56                 cvZero(tmp_image);
57                 cvDrawContours( tmp_image, &seq, CV_RGB(0, 0, 255), CV_RGB(0, 0, 255), 10, -1);
58                 int num1 = cvCountNonZero(tmp_image);
59         cvAnd(tmp_image, bg_model->foreground, tmp_image);
60                 int num2 = cvCountNonZero(tmp_image);
61                 if( num2 > num1*0.5 )
62                         cvDrawContours( bg_model->foreground, &seq, CV_RGB(0, 0, 255), CV_RGB(0, 0, 255), 10, -1);
63                 else
64                         cvDrawContours( bg_model->foreground, &seq, CV_RGB(0, 0, 0), CV_RGB(0, 0, 0), 10, -1);
65         }
66         cvReleaseImage(&tmp_image);
67 }
68
69 /* End of file. */
70