feature_evaluator.cpp 4.64 KB
Newer Older
1 2 3 4
/*
By downloading, copying, installing or using the software you agree to this license.
If you do not agree to this license, do not download, install,
copy or use the software.
Vlad Shakhuro's avatar
Vlad Shakhuro committed
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

                          License Agreement
               For Open Source Computer Vision Library
                       (3-clause BSD License)

Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved.
Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
Copyright (C) 2015, OpenCV Foundation, all rights reserved.
Copyright (C) 2015, Itseez Inc., all rights reserved.
Third party copyrights are property of their respective owners.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

  * Neither the names of the copyright holders nor the names of the contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.

This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are disclaimed.
In no event shall copyright holders or contributors be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused
and on any theory of liability, whether in contract, strict liability,
or tort (including negligence or otherwise) arising in any way out of
the use of this software, even if advised of the possibility of such damage.
*/

#include "precomp.hpp"
Vlad Shakhuro's avatar
Vlad Shakhuro committed
46

Vlad Shakhuro's avatar
Vlad Shakhuro committed
47 48
namespace cv {
namespace xobjdetect {
Vlad Shakhuro's avatar
Vlad Shakhuro committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

float calcNormFactor( const Mat& sum, const Mat& sqSum )
{
    CV_DbgAssert( sum.cols > 3 && sqSum.rows > 3 );
    Rect normrect( 1, 1, sum.cols - 3, sum.rows - 3 );
    size_t p0, p1, p2, p3;
    CV_SUM_OFFSETS( p0, p1, p2, p3, normrect, sum.step1() )
    double area = normrect.width * normrect.height;
    const int *sp = sum.ptr<int>();
    int valSum = sp[p0] - sp[p1] - sp[p2] + sp[p3];
    const double *sqp = sqSum.ptr<double>();
    double valSqSum = sqp[p0] - sqp[p1] - sqp[p2] + sqp[p3];
    return (float) sqrt( (double) (area * valSqSum - (double)valSum * valSum) );
}

CvParams::CvParams() : name( "params" ) {}
void CvParams::printDefaults() const
Vlad Shakhuro's avatar
Vlad Shakhuro committed
66
{ std::cout << "--" << name << "--" << std::endl; }
Vlad Shakhuro's avatar
Vlad Shakhuro committed
67
void CvParams::printAttrs() const {}
Vlad Shakhuro's avatar
Vlad Shakhuro committed
68
bool CvParams::scanAttr( const std::string, const std::string ) { return false; }
Vlad Shakhuro's avatar
Vlad Shakhuro committed
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


//---------------------------- FeatureParams --------------------------------------

CvFeatureParams::CvFeatureParams() : maxCatCount( 0 ), featSize( 1 )
{
    name = CC_FEATURE_PARAMS;
}

void CvFeatureParams::init( const CvFeatureParams& fp )
{
    maxCatCount = fp.maxCatCount;
    featSize = fp.featSize;
}

void CvFeatureParams::write( FileStorage &fs ) const
{
    fs << CC_MAX_CAT_COUNT << maxCatCount;
    fs << CC_FEATURE_SIZE << featSize;
}

bool CvFeatureParams::read( const FileNode &node )
{
    if ( node.empty() )
        return false;
    maxCatCount = node[CC_MAX_CAT_COUNT];
    featSize = node[CC_FEATURE_SIZE];
    return ( maxCatCount >= 0 && featSize >= 1 );
}

Vlad Shakhuro's avatar
Vlad Shakhuro committed
99
Ptr<CvFeatureParams> CvFeatureParams::create()
Vlad Shakhuro's avatar
Vlad Shakhuro committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
{
    return Ptr<CvFeatureParams>(new CvLBPFeatureParams);
}

//------------------------------------- FeatureEvaluator ---------------------------------------

void CvFeatureEvaluator::init(const CvFeatureParams *_featureParams,
                              int _maxSampleCount, Size _winSize )
{
    CV_Assert(_maxSampleCount > 0);
    featureParams = (CvFeatureParams *)_featureParams;
    winSize = _winSize;
    numFeatures = 0;
    cls.create( (int)_maxSampleCount, 1, CV_32FC1 );
    generateFeatures();
}

Vlad Shakhuro's avatar
Vlad Shakhuro committed
117
void CvFeatureEvaluator::setImage(const Mat &, uchar clsLabel, int idx, const std::vector<int>&)
Vlad Shakhuro's avatar
Vlad Shakhuro committed
118 119 120 121 122 123 124
{
    //CV_Assert(img.cols == winSize.width);
    //CV_Assert(img.rows == winSize.height);
    CV_Assert(idx < cls.rows);
    cls.ptr<float>(idx)[0] = clsLabel;
}

Vlad Shakhuro's avatar
Vlad Shakhuro committed
125
Ptr<CvFeatureEvaluator> CvFeatureEvaluator::create()
Vlad Shakhuro's avatar
Vlad Shakhuro committed
126 127 128
{
    return Ptr<CvFeatureEvaluator>(new CvLBPEvaluator);
}
Vlad Shakhuro's avatar
Vlad Shakhuro committed
129 130 131

}
}