opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
joeverbout 0:ea44dc9ed014 16 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 17 //
joeverbout 0:ea44dc9ed014 18 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 19 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 20 //
joeverbout 0:ea44dc9ed014 21 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 22 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 23 //
joeverbout 0:ea44dc9ed014 24 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 25 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 26 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 27 //
joeverbout 0:ea44dc9ed014 28 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 29 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 30 //
joeverbout 0:ea44dc9ed014 31 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 32 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 34 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 35 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 36 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 37 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 38 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 39 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 40 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 41 //
joeverbout 0:ea44dc9ed014 42 //M*/
joeverbout 0:ea44dc9ed014 43
joeverbout 0:ea44dc9ed014 44 #ifndef __OPENCV_SHAPE_SHAPE_DISTANCE_HPP__
joeverbout 0:ea44dc9ed014 45 #define __OPENCV_SHAPE_SHAPE_DISTANCE_HPP__
joeverbout 0:ea44dc9ed014 46 #include "opencv2/core.hpp"
joeverbout 0:ea44dc9ed014 47 #include "opencv2/shape/hist_cost.hpp"
joeverbout 0:ea44dc9ed014 48 #include "opencv2/shape/shape_transformer.hpp"
joeverbout 0:ea44dc9ed014 49
joeverbout 0:ea44dc9ed014 50 namespace cv
joeverbout 0:ea44dc9ed014 51 {
joeverbout 0:ea44dc9ed014 52
joeverbout 0:ea44dc9ed014 53 //! @addtogroup shape
joeverbout 0:ea44dc9ed014 54 //! @{
joeverbout 0:ea44dc9ed014 55
joeverbout 0:ea44dc9ed014 56 /** @brief Abstract base class for shape distance algorithms.
joeverbout 0:ea44dc9ed014 57 */
joeverbout 0:ea44dc9ed014 58 class CV_EXPORTS_W ShapeDistanceExtractor : public Algorithm
joeverbout 0:ea44dc9ed014 59 {
joeverbout 0:ea44dc9ed014 60 public:
joeverbout 0:ea44dc9ed014 61 /** @brief Compute the shape distance between two shapes defined by its contours.
joeverbout 0:ea44dc9ed014 62
joeverbout 0:ea44dc9ed014 63 @param contour1 Contour defining first shape.
joeverbout 0:ea44dc9ed014 64 @param contour2 Contour defining second shape.
joeverbout 0:ea44dc9ed014 65 */
joeverbout 0:ea44dc9ed014 66 CV_WRAP virtual float computeDistance(InputArray contour1, InputArray contour2) = 0;
joeverbout 0:ea44dc9ed014 67 };
joeverbout 0:ea44dc9ed014 68
joeverbout 0:ea44dc9ed014 69 /***********************************************************************************/
joeverbout 0:ea44dc9ed014 70 /***********************************************************************************/
joeverbout 0:ea44dc9ed014 71 /***********************************************************************************/
joeverbout 0:ea44dc9ed014 72 /** @brief Implementation of the Shape Context descriptor and matching algorithm
joeverbout 0:ea44dc9ed014 73
joeverbout 0:ea44dc9ed014 74 proposed by Belongie et al. in "Shape Matching and Object Recognition Using Shape Contexts" (PAMI
joeverbout 0:ea44dc9ed014 75 2002). This implementation is packaged in a generic scheme, in order to allow you the
joeverbout 0:ea44dc9ed014 76 implementation of the common variations of the original pipeline.
joeverbout 0:ea44dc9ed014 77 */
joeverbout 0:ea44dc9ed014 78 class CV_EXPORTS_W ShapeContextDistanceExtractor : public ShapeDistanceExtractor
joeverbout 0:ea44dc9ed014 79 {
joeverbout 0:ea44dc9ed014 80 public:
joeverbout 0:ea44dc9ed014 81 /** @brief Establish the number of angular bins for the Shape Context Descriptor used in the shape matching
joeverbout 0:ea44dc9ed014 82 pipeline.
joeverbout 0:ea44dc9ed014 83
joeverbout 0:ea44dc9ed014 84 @param nAngularBins The number of angular bins in the shape context descriptor.
joeverbout 0:ea44dc9ed014 85 */
joeverbout 0:ea44dc9ed014 86 CV_WRAP virtual void setAngularBins(int nAngularBins) = 0;
joeverbout 0:ea44dc9ed014 87 CV_WRAP virtual int getAngularBins() const = 0;
joeverbout 0:ea44dc9ed014 88
joeverbout 0:ea44dc9ed014 89 /** @brief Establish the number of radial bins for the Shape Context Descriptor used in the shape matching
joeverbout 0:ea44dc9ed014 90 pipeline.
joeverbout 0:ea44dc9ed014 91
joeverbout 0:ea44dc9ed014 92 @param nRadialBins The number of radial bins in the shape context descriptor.
joeverbout 0:ea44dc9ed014 93 */
joeverbout 0:ea44dc9ed014 94 CV_WRAP virtual void setRadialBins(int nRadialBins) = 0;
joeverbout 0:ea44dc9ed014 95 CV_WRAP virtual int getRadialBins() const = 0;
joeverbout 0:ea44dc9ed014 96
joeverbout 0:ea44dc9ed014 97 /** @brief Set the inner radius of the shape context descriptor.
joeverbout 0:ea44dc9ed014 98
joeverbout 0:ea44dc9ed014 99 @param innerRadius The value of the inner radius.
joeverbout 0:ea44dc9ed014 100 */
joeverbout 0:ea44dc9ed014 101 CV_WRAP virtual void setInnerRadius(float innerRadius) = 0;
joeverbout 0:ea44dc9ed014 102 CV_WRAP virtual float getInnerRadius() const = 0;
joeverbout 0:ea44dc9ed014 103
joeverbout 0:ea44dc9ed014 104 /** @brief Set the outer radius of the shape context descriptor.
joeverbout 0:ea44dc9ed014 105
joeverbout 0:ea44dc9ed014 106 @param outerRadius The value of the outer radius.
joeverbout 0:ea44dc9ed014 107 */
joeverbout 0:ea44dc9ed014 108 CV_WRAP virtual void setOuterRadius(float outerRadius) = 0;
joeverbout 0:ea44dc9ed014 109 CV_WRAP virtual float getOuterRadius() const = 0;
joeverbout 0:ea44dc9ed014 110
joeverbout 0:ea44dc9ed014 111 CV_WRAP virtual void setRotationInvariant(bool rotationInvariant) = 0;
joeverbout 0:ea44dc9ed014 112 CV_WRAP virtual bool getRotationInvariant() const = 0;
joeverbout 0:ea44dc9ed014 113
joeverbout 0:ea44dc9ed014 114 /** @brief Set the weight of the shape context distance in the final value of the shape distance. The shape
joeverbout 0:ea44dc9ed014 115 context distance between two shapes is defined as the symmetric sum of shape context matching costs
joeverbout 0:ea44dc9ed014 116 over best matching points. The final value of the shape distance is a user-defined linear
joeverbout 0:ea44dc9ed014 117 combination of the shape context distance, an image appearance distance, and a bending energy.
joeverbout 0:ea44dc9ed014 118
joeverbout 0:ea44dc9ed014 119 @param shapeContextWeight The weight of the shape context distance in the final distance value.
joeverbout 0:ea44dc9ed014 120 */
joeverbout 0:ea44dc9ed014 121 CV_WRAP virtual void setShapeContextWeight(float shapeContextWeight) = 0;
joeverbout 0:ea44dc9ed014 122 CV_WRAP virtual float getShapeContextWeight() const = 0;
joeverbout 0:ea44dc9ed014 123
joeverbout 0:ea44dc9ed014 124 /** @brief Set the weight of the Image Appearance cost in the final value of the shape distance. The image
joeverbout 0:ea44dc9ed014 125 appearance cost is defined as the sum of squared brightness differences in Gaussian windows around
joeverbout 0:ea44dc9ed014 126 corresponding image points. The final value of the shape distance is a user-defined linear
joeverbout 0:ea44dc9ed014 127 combination of the shape context distance, an image appearance distance, and a bending energy. If
joeverbout 0:ea44dc9ed014 128 this value is set to a number different from 0, is mandatory to set the images that correspond to
joeverbout 0:ea44dc9ed014 129 each shape.
joeverbout 0:ea44dc9ed014 130
joeverbout 0:ea44dc9ed014 131 @param imageAppearanceWeight The weight of the appearance cost in the final distance value.
joeverbout 0:ea44dc9ed014 132 */
joeverbout 0:ea44dc9ed014 133 CV_WRAP virtual void setImageAppearanceWeight(float imageAppearanceWeight) = 0;
joeverbout 0:ea44dc9ed014 134 CV_WRAP virtual float getImageAppearanceWeight() const = 0;
joeverbout 0:ea44dc9ed014 135
joeverbout 0:ea44dc9ed014 136 /** @brief Set the weight of the Bending Energy in the final value of the shape distance. The bending energy
joeverbout 0:ea44dc9ed014 137 definition depends on what transformation is being used to align the shapes. The final value of the
joeverbout 0:ea44dc9ed014 138 shape distance is a user-defined linear combination of the shape context distance, an image
joeverbout 0:ea44dc9ed014 139 appearance distance, and a bending energy.
joeverbout 0:ea44dc9ed014 140
joeverbout 0:ea44dc9ed014 141 @param bendingEnergyWeight The weight of the Bending Energy in the final distance value.
joeverbout 0:ea44dc9ed014 142 */
joeverbout 0:ea44dc9ed014 143 CV_WRAP virtual void setBendingEnergyWeight(float bendingEnergyWeight) = 0;
joeverbout 0:ea44dc9ed014 144 CV_WRAP virtual float getBendingEnergyWeight() const = 0;
joeverbout 0:ea44dc9ed014 145
joeverbout 0:ea44dc9ed014 146 /** @brief Set the images that correspond to each shape. This images are used in the calculation of the Image
joeverbout 0:ea44dc9ed014 147 Appearance cost.
joeverbout 0:ea44dc9ed014 148
joeverbout 0:ea44dc9ed014 149 @param image1 Image corresponding to the shape defined by contours1.
joeverbout 0:ea44dc9ed014 150 @param image2 Image corresponding to the shape defined by contours2.
joeverbout 0:ea44dc9ed014 151 */
joeverbout 0:ea44dc9ed014 152 CV_WRAP virtual void setImages(InputArray image1, InputArray image2) = 0;
joeverbout 0:ea44dc9ed014 153 CV_WRAP virtual void getImages(OutputArray image1, OutputArray image2) const = 0;
joeverbout 0:ea44dc9ed014 154
joeverbout 0:ea44dc9ed014 155 CV_WRAP virtual void setIterations(int iterations) = 0;
joeverbout 0:ea44dc9ed014 156 CV_WRAP virtual int getIterations() const = 0;
joeverbout 0:ea44dc9ed014 157
joeverbout 0:ea44dc9ed014 158 /** @brief Set the algorithm used for building the shape context descriptor cost matrix.
joeverbout 0:ea44dc9ed014 159
joeverbout 0:ea44dc9ed014 160 @param comparer Smart pointer to a HistogramCostExtractor, an algorithm that defines the cost
joeverbout 0:ea44dc9ed014 161 matrix between descriptors.
joeverbout 0:ea44dc9ed014 162 */
joeverbout 0:ea44dc9ed014 163 CV_WRAP virtual void setCostExtractor(Ptr<HistogramCostExtractor> comparer) = 0;
joeverbout 0:ea44dc9ed014 164 CV_WRAP virtual Ptr<HistogramCostExtractor> getCostExtractor() const = 0;
joeverbout 0:ea44dc9ed014 165
joeverbout 0:ea44dc9ed014 166 /** @brief Set the value of the standard deviation for the Gaussian window for the image appearance cost.
joeverbout 0:ea44dc9ed014 167
joeverbout 0:ea44dc9ed014 168 @param sigma Standard Deviation.
joeverbout 0:ea44dc9ed014 169 */
joeverbout 0:ea44dc9ed014 170 CV_WRAP virtual void setStdDev(float sigma) = 0;
joeverbout 0:ea44dc9ed014 171 CV_WRAP virtual float getStdDev() const = 0;
joeverbout 0:ea44dc9ed014 172
joeverbout 0:ea44dc9ed014 173 /** @brief Set the algorithm used for aligning the shapes.
joeverbout 0:ea44dc9ed014 174
joeverbout 0:ea44dc9ed014 175 @param transformer Smart pointer to a ShapeTransformer, an algorithm that defines the aligning
joeverbout 0:ea44dc9ed014 176 transformation.
joeverbout 0:ea44dc9ed014 177 */
joeverbout 0:ea44dc9ed014 178 CV_WRAP virtual void setTransformAlgorithm(Ptr<ShapeTransformer> transformer) = 0;
joeverbout 0:ea44dc9ed014 179 CV_WRAP virtual Ptr<ShapeTransformer> getTransformAlgorithm() const = 0;
joeverbout 0:ea44dc9ed014 180 };
joeverbout 0:ea44dc9ed014 181
joeverbout 0:ea44dc9ed014 182 /* Complete constructor */
joeverbout 0:ea44dc9ed014 183 CV_EXPORTS_W Ptr<ShapeContextDistanceExtractor>
joeverbout 0:ea44dc9ed014 184 createShapeContextDistanceExtractor(int nAngularBins=12, int nRadialBins=4,
joeverbout 0:ea44dc9ed014 185 float innerRadius=0.2f, float outerRadius=2, int iterations=3,
joeverbout 0:ea44dc9ed014 186 const Ptr<HistogramCostExtractor> &comparer = createChiHistogramCostExtractor(),
joeverbout 0:ea44dc9ed014 187 const Ptr<ShapeTransformer> &transformer = createThinPlateSplineShapeTransformer());
joeverbout 0:ea44dc9ed014 188
joeverbout 0:ea44dc9ed014 189 /***********************************************************************************/
joeverbout 0:ea44dc9ed014 190 /***********************************************************************************/
joeverbout 0:ea44dc9ed014 191 /***********************************************************************************/
joeverbout 0:ea44dc9ed014 192 /** @brief A simple Hausdorff distance measure between shapes defined by contours
joeverbout 0:ea44dc9ed014 193
joeverbout 0:ea44dc9ed014 194 according to the paper "Comparing Images using the Hausdorff distance." by D.P. Huttenlocher, G.A.
joeverbout 0:ea44dc9ed014 195 Klanderman, and W.J. Rucklidge. (PAMI 1993). :
joeverbout 0:ea44dc9ed014 196 */
joeverbout 0:ea44dc9ed014 197 class CV_EXPORTS_W HausdorffDistanceExtractor : public ShapeDistanceExtractor
joeverbout 0:ea44dc9ed014 198 {
joeverbout 0:ea44dc9ed014 199 public:
joeverbout 0:ea44dc9ed014 200 /** @brief Set the norm used to compute the Hausdorff value between two shapes. It can be L1 or L2 norm.
joeverbout 0:ea44dc9ed014 201
joeverbout 0:ea44dc9ed014 202 @param distanceFlag Flag indicating which norm is used to compute the Hausdorff distance
joeverbout 0:ea44dc9ed014 203 (NORM_L1, NORM_L2).
joeverbout 0:ea44dc9ed014 204 */
joeverbout 0:ea44dc9ed014 205 CV_WRAP virtual void setDistanceFlag(int distanceFlag) = 0;
joeverbout 0:ea44dc9ed014 206 CV_WRAP virtual int getDistanceFlag() const = 0;
joeverbout 0:ea44dc9ed014 207
joeverbout 0:ea44dc9ed014 208 /** @brief This method sets the rank proportion (or fractional value) that establish the Kth ranked value of
joeverbout 0:ea44dc9ed014 209 the partial Hausdorff distance. Experimentally had been shown that 0.6 is a good value to compare
joeverbout 0:ea44dc9ed014 210 shapes.
joeverbout 0:ea44dc9ed014 211
joeverbout 0:ea44dc9ed014 212 @param rankProportion fractional value (between 0 and 1).
joeverbout 0:ea44dc9ed014 213 */
joeverbout 0:ea44dc9ed014 214 CV_WRAP virtual void setRankProportion(float rankProportion) = 0;
joeverbout 0:ea44dc9ed014 215 CV_WRAP virtual float getRankProportion() const = 0;
joeverbout 0:ea44dc9ed014 216 };
joeverbout 0:ea44dc9ed014 217
joeverbout 0:ea44dc9ed014 218 /* Constructor */
joeverbout 0:ea44dc9ed014 219 CV_EXPORTS_W Ptr<HausdorffDistanceExtractor> createHausdorffDistanceExtractor(int distanceFlag=cv::NORM_L2, float rankProp=0.6f);
joeverbout 0:ea44dc9ed014 220
joeverbout 0:ea44dc9ed014 221 //! @}
joeverbout 0:ea44dc9ed014 222
joeverbout 0:ea44dc9ed014 223 } // cv
joeverbout 0:ea44dc9ed014 224 #endif
joeverbout 0:ea44dc9ed014 225