Home | History | Annotate | Download | only in src
      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 #include "_cvaux.h"
     42 
     43 #define CV_MAX2( a, b ) ((a)>(b) ? (a) : (b))
     44 #define CV_MIN2( a, b ) ((a)<(b) ? (a) : (b))
     45 
     46 /****************************************************************************************\
     47 
     48    create hand mask
     49 
     50 \****************************************************************************************/
     51 
     52 static CvStatus icvCreateHandMask8uC1R(CvSeq * numbers,
     53                                        uchar * image_mask, int step,
     54                                        CvSize size, CvRect * roi )
     55 {
     56 
     57     CvSeqReader reader;
     58     CvPoint pt;
     59     int k_point;
     60     int i_min, i_max, j_min, j_max;
     61 
     62     if( numbers == NULL )
     63         return CV_NULLPTR_ERR;
     64 
     65     if( !CV_IS_SEQ_POINT_SET( numbers ))
     66         return CV_BADFLAG_ERR;
     67 
     68     i_max = j_max = 0;
     69     i_min = size.height;
     70     j_min = size.width;
     71 
     72     cvStartReadSeq( numbers, &reader, 0 );
     73 
     74     k_point = numbers->total;
     75     assert( k_point > 0 );
     76     if( k_point <= 0 )
     77         return CV_BADSIZE_ERR;
     78 
     79     memset( image_mask, 0, step * size.height );
     80 
     81     while( k_point-- > 0 )
     82     {
     83         CV_READ_SEQ_ELEM( pt, reader );
     84 
     85         i_min = CV_MIN2( i_min, pt.y );
     86         i_max = CV_MAX2( i_max, pt.y );
     87         j_min = CV_MIN2( j_min, pt.x );
     88         j_max = CV_MAX2( j_max, pt.x );
     89 
     90         *(image_mask + pt.y * step + pt.x) = 255;
     91     }
     92 
     93     roi->x = j_min;
     94     roi->y = i_min;
     95     roi->width = j_max - j_min + 1;
     96     roi->height = i_max - i_min + 1;
     97 
     98     return CV_OK;
     99 
    100 }
    101 
    102 
    103 /*F///////////////////////////////////////////////////////////////////////////////////////
    104 //    Name:     cvCreateHandMask
    105 //    Purpose:  creates hand mask image
    106 //    Context:
    107 //    Parameters:
    108 //      numbers - pointer to the input sequence of the point's indexes inside
    109 //                hand region
    110 //      img_mask - pointer to the result mask image
    111 //      roi      - result hand mask ROI
    112 //
    113 //    Notes:
    114 //F*/
    115 CV_IMPL void
    116 cvCreateHandMask( CvSeq * numbers, IplImage * img_mask, CvRect * roi )
    117 {
    118     uchar *img_mask_data = 0;
    119     int img_mask_step = 0;
    120     CvSize img_mask_size;
    121 
    122     CV_FUNCNAME( "cvCreateHandMask" );
    123 
    124     __BEGIN__;
    125 
    126     if( img_mask->depth != IPL_DEPTH_8U )
    127         CV_ERROR( CV_BadDepth, cvUnsupportedFormat );
    128 
    129     if( img_mask->nChannels != 1 )
    130         CV_ERROR( CV_BadNumChannels, "output image have wrong number of channels" );
    131 
    132     cvGetImageRawData( img_mask, &img_mask_data, &img_mask_step, &img_mask_size );
    133 
    134     IPPI_CALL( icvCreateHandMask8uC1R( numbers, img_mask_data,
    135                                         img_mask_step, img_mask_size, roi ));
    136 
    137     __END__;
    138 }
    139