Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers predict_collector.hpp Source File

predict_collector.hpp

00001 /*
00002 By downloading, copying, installing or using the software you agree to this license.
00003 If you do not agree to this license, do not download, install,
00004 copy or use the software.
00005 
00006 
00007                           License Agreement
00008                For Open Source Computer Vision Library
00009                        (3-clause BSD License)
00010 
00011 Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
00012 Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
00013 Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved.
00014 Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
00015 Copyright (C) 2015, OpenCV Foundation, all rights reserved.
00016 Copyright (C) 2015, Itseez Inc., all rights reserved.
00017 Third party copyrights are property of their respective owners.
00018 
00019 Redistribution and use in source and binary forms, with or without modification,
00020 are permitted provided that the following conditions are met:
00021 
00022   * Redistributions of source code must retain the above copyright notice,
00023     this list of conditions and the following disclaimer.
00024 
00025   * Redistributions in binary form must reproduce the above copyright notice,
00026     this list of conditions and the following disclaimer in the documentation
00027     and/or other materials provided with the distribution.
00028 
00029   * Neither the names of the copyright holders nor the names of the contributors
00030     may be used to endorse or promote products derived from this software
00031     without specific prior written permission.
00032 
00033 This software is provided by the copyright holders and contributors "as is" and
00034 any express or implied warranties, including, but not limited to, the implied
00035 warranties of merchantability and fitness for a particular purpose are disclaimed.
00036 In no event shall copyright holders or contributors be liable for any direct,
00037 indirect, incidental, special, exemplary, or consequential damages
00038 (including, but not limited to, procurement of substitute goods or services;
00039 loss of use, data, or profits; or business interruption) however caused
00040 and on any theory of liability, whether in contract, strict liability,
00041 or tort (including negligence or otherwise) arising in any way out of
00042 the use of this software, even if advised of the possibility of such damage.
00043 */
00044 
00045 #ifndef __OPENCV_PREDICT_COLLECTOR_HPP__
00046 #define __OPENCV_PREDICT_COLLECTOR_HPP__
00047 
00048 #include <vector>
00049 #include <map>
00050 #include <utility>
00051 #include <cfloat>
00052 
00053 #include "opencv2/core/cvstd.hpp"
00054 
00055 namespace cv {
00056 namespace face {
00057 //! @addtogroup face
00058 //! @{
00059 /** @brief Abstract base class for all strategies of prediction result handling
00060 */
00061 class CV_EXPORTS_W PredictCollector
00062 {
00063 public:
00064     virtual ~PredictCollector() {}
00065 
00066     /** @brief Interface method called by face recognizer before results processing
00067     @param size total size of prediction evaluation that recognizer could perform
00068     */
00069     virtual void init(size_t size) { (void)size; }
00070 
00071     /** @brief Interface method called by face recognizer for each result
00072     @param label current prediction label
00073     @param dist current prediction distance (confidence)
00074     */
00075     virtual bool collect(int label, double dist) = 0;
00076 };
00077 
00078 /** @brief Default predict collector
00079 
00080 Trace minimal distance with treshhold checking (that is default behavior for most predict logic)
00081 */
00082 class CV_EXPORTS_W StandardCollector : public PredictCollector
00083 {
00084 public:
00085     struct PredictResult
00086     {
00087         int label;
00088         double distance;
00089         PredictResult(int label_ = -1, double distance_ = DBL_MAX) : label(label_), distance(distance_) {}
00090     };
00091 protected:
00092     double threshold;
00093     PredictResult minRes;
00094     std::vector<PredictResult> data;
00095 public:
00096     /** @brief Constructor
00097     @param threshold_ set threshold
00098     */
00099     StandardCollector(double threshold_ = DBL_MAX);
00100     /** @brief overloaded interface method */
00101     void init(size_t size);
00102     /** @brief overloaded interface method */
00103     bool collect(int label, double dist);
00104     /** @brief Returns label with minimal distance */
00105     CV_WRAP int getMinLabel() const;
00106     /** @brief Returns minimal distance value */
00107     CV_WRAP double getMinDist() const;
00108     /** @brief Return results as vector
00109     @param sorted If set, results will be sorted by distance
00110     Each values is a pair of label and distance.
00111     */
00112     CV_WRAP std::vector< std::pair<int, double> > getResults(bool sorted = false) const;
00113     /** @brief Return results as map
00114     Labels are keys, values are minimal distances
00115     */
00116     std::map<int, double> getResultsMap() const;
00117     /** @brief Static constructor
00118     @param threshold set threshold
00119     */
00120     CV_WRAP static Ptr<StandardCollector> create(double threshold = DBL_MAX);
00121 };
00122 
00123 //! @}
00124 }
00125 }
00126 
00127 #endif
00128