openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

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