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 /***********************************************************************
RyoheiHagimoto 0:0e0631af0305 2 * Software License Agreement (BSD License)
RyoheiHagimoto 0:0e0631af0305 3 *
RyoheiHagimoto 0:0e0631af0305 4 * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
RyoheiHagimoto 0:0e0631af0305 5 * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
RyoheiHagimoto 0:0e0631af0305 6 *
RyoheiHagimoto 0:0e0631af0305 7 * THE BSD LICENSE
RyoheiHagimoto 0:0e0631af0305 8 *
RyoheiHagimoto 0:0e0631af0305 9 * Redistribution and use in source and binary forms, with or without
RyoheiHagimoto 0:0e0631af0305 10 * modification, are permitted provided that the following conditions
RyoheiHagimoto 0:0e0631af0305 11 * are met:
RyoheiHagimoto 0:0e0631af0305 12 *
RyoheiHagimoto 0:0e0631af0305 13 * 1. Redistributions of source code must retain the above copyright
RyoheiHagimoto 0:0e0631af0305 14 * notice, this list of conditions and the following disclaimer.
RyoheiHagimoto 0:0e0631af0305 15 * 2. Redistributions in binary form must reproduce the above copyright
RyoheiHagimoto 0:0e0631af0305 16 * notice, this list of conditions and the following disclaimer in the
RyoheiHagimoto 0:0e0631af0305 17 * documentation and/or other materials provided with the distribution.
RyoheiHagimoto 0:0e0631af0305 18 *
RyoheiHagimoto 0:0e0631af0305 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
RyoheiHagimoto 0:0e0631af0305 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
RyoheiHagimoto 0:0e0631af0305 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
RyoheiHagimoto 0:0e0631af0305 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
RyoheiHagimoto 0:0e0631af0305 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
RyoheiHagimoto 0:0e0631af0305 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
RyoheiHagimoto 0:0e0631af0305 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
RyoheiHagimoto 0:0e0631af0305 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
RyoheiHagimoto 0:0e0631af0305 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
RyoheiHagimoto 0:0e0631af0305 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
RyoheiHagimoto 0:0e0631af0305 29 *************************************************************************/
RyoheiHagimoto 0:0e0631af0305 30
RyoheiHagimoto 0:0e0631af0305 31 #ifndef OPENCV_FLANN_LINEAR_INDEX_H_
RyoheiHagimoto 0:0e0631af0305 32 #define OPENCV_FLANN_LINEAR_INDEX_H_
RyoheiHagimoto 0:0e0631af0305 33
RyoheiHagimoto 0:0e0631af0305 34 #include "general.h"
RyoheiHagimoto 0:0e0631af0305 35 #include "nn_index.h"
RyoheiHagimoto 0:0e0631af0305 36
RyoheiHagimoto 0:0e0631af0305 37 namespace cvflann
RyoheiHagimoto 0:0e0631af0305 38 {
RyoheiHagimoto 0:0e0631af0305 39
RyoheiHagimoto 0:0e0631af0305 40 struct LinearIndexParams : public IndexParams
RyoheiHagimoto 0:0e0631af0305 41 {
RyoheiHagimoto 0:0e0631af0305 42 LinearIndexParams()
RyoheiHagimoto 0:0e0631af0305 43 {
RyoheiHagimoto 0:0e0631af0305 44 (* this)["algorithm"] = FLANN_INDEX_LINEAR;
RyoheiHagimoto 0:0e0631af0305 45 }
RyoheiHagimoto 0:0e0631af0305 46 };
RyoheiHagimoto 0:0e0631af0305 47
RyoheiHagimoto 0:0e0631af0305 48 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 49 class LinearIndex : public NNIndex<Distance>
RyoheiHagimoto 0:0e0631af0305 50 {
RyoheiHagimoto 0:0e0631af0305 51 public:
RyoheiHagimoto 0:0e0631af0305 52
RyoheiHagimoto 0:0e0631af0305 53 typedef typename Distance::ElementType ElementType;
RyoheiHagimoto 0:0e0631af0305 54 typedef typename Distance::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 55
RyoheiHagimoto 0:0e0631af0305 56
RyoheiHagimoto 0:0e0631af0305 57 LinearIndex(const Matrix<ElementType>& inputData, const IndexParams& params = LinearIndexParams(),
RyoheiHagimoto 0:0e0631af0305 58 Distance d = Distance()) :
RyoheiHagimoto 0:0e0631af0305 59 dataset_(inputData), index_params_(params), distance_(d)
RyoheiHagimoto 0:0e0631af0305 60 {
RyoheiHagimoto 0:0e0631af0305 61 }
RyoheiHagimoto 0:0e0631af0305 62
RyoheiHagimoto 0:0e0631af0305 63 LinearIndex(const LinearIndex&);
RyoheiHagimoto 0:0e0631af0305 64 LinearIndex& operator=(const LinearIndex&);
RyoheiHagimoto 0:0e0631af0305 65
RyoheiHagimoto 0:0e0631af0305 66 flann_algorithm_t getType() const
RyoheiHagimoto 0:0e0631af0305 67 {
RyoheiHagimoto 0:0e0631af0305 68 return FLANN_INDEX_LINEAR;
RyoheiHagimoto 0:0e0631af0305 69 }
RyoheiHagimoto 0:0e0631af0305 70
RyoheiHagimoto 0:0e0631af0305 71
RyoheiHagimoto 0:0e0631af0305 72 size_t size() const
RyoheiHagimoto 0:0e0631af0305 73 {
RyoheiHagimoto 0:0e0631af0305 74 return dataset_.rows;
RyoheiHagimoto 0:0e0631af0305 75 }
RyoheiHagimoto 0:0e0631af0305 76
RyoheiHagimoto 0:0e0631af0305 77 size_t veclen() const
RyoheiHagimoto 0:0e0631af0305 78 {
RyoheiHagimoto 0:0e0631af0305 79 return dataset_.cols;
RyoheiHagimoto 0:0e0631af0305 80 }
RyoheiHagimoto 0:0e0631af0305 81
RyoheiHagimoto 0:0e0631af0305 82
RyoheiHagimoto 0:0e0631af0305 83 int usedMemory() const
RyoheiHagimoto 0:0e0631af0305 84 {
RyoheiHagimoto 0:0e0631af0305 85 return 0;
RyoheiHagimoto 0:0e0631af0305 86 }
RyoheiHagimoto 0:0e0631af0305 87
RyoheiHagimoto 0:0e0631af0305 88 void buildIndex()
RyoheiHagimoto 0:0e0631af0305 89 {
RyoheiHagimoto 0:0e0631af0305 90 /* nothing to do here for linear search */
RyoheiHagimoto 0:0e0631af0305 91 }
RyoheiHagimoto 0:0e0631af0305 92
RyoheiHagimoto 0:0e0631af0305 93 void saveIndex(FILE*)
RyoheiHagimoto 0:0e0631af0305 94 {
RyoheiHagimoto 0:0e0631af0305 95 /* nothing to do here for linear search */
RyoheiHagimoto 0:0e0631af0305 96 }
RyoheiHagimoto 0:0e0631af0305 97
RyoheiHagimoto 0:0e0631af0305 98
RyoheiHagimoto 0:0e0631af0305 99 void loadIndex(FILE*)
RyoheiHagimoto 0:0e0631af0305 100 {
RyoheiHagimoto 0:0e0631af0305 101 /* nothing to do here for linear search */
RyoheiHagimoto 0:0e0631af0305 102
RyoheiHagimoto 0:0e0631af0305 103 index_params_["algorithm"] = getType();
RyoheiHagimoto 0:0e0631af0305 104 }
RyoheiHagimoto 0:0e0631af0305 105
RyoheiHagimoto 0:0e0631af0305 106 void findNeighbors(ResultSet<DistanceType>& resultSet, const ElementType* vec, const SearchParams& /*searchParams*/)
RyoheiHagimoto 0:0e0631af0305 107 {
RyoheiHagimoto 0:0e0631af0305 108 ElementType* data = dataset_.data;
RyoheiHagimoto 0:0e0631af0305 109 for (size_t i = 0; i < dataset_.rows; ++i, data += dataset_.cols) {
RyoheiHagimoto 0:0e0631af0305 110 DistanceType dist = distance_(data, vec, dataset_.cols);
RyoheiHagimoto 0:0e0631af0305 111 resultSet.addPoint(dist, (int)i);
RyoheiHagimoto 0:0e0631af0305 112 }
RyoheiHagimoto 0:0e0631af0305 113 }
RyoheiHagimoto 0:0e0631af0305 114
RyoheiHagimoto 0:0e0631af0305 115 IndexParams getParameters() const
RyoheiHagimoto 0:0e0631af0305 116 {
RyoheiHagimoto 0:0e0631af0305 117 return index_params_;
RyoheiHagimoto 0:0e0631af0305 118 }
RyoheiHagimoto 0:0e0631af0305 119
RyoheiHagimoto 0:0e0631af0305 120 private:
RyoheiHagimoto 0:0e0631af0305 121 /** The dataset */
RyoheiHagimoto 0:0e0631af0305 122 const Matrix<ElementType> dataset_;
RyoheiHagimoto 0:0e0631af0305 123 /** Index parameters */
RyoheiHagimoto 0:0e0631af0305 124 IndexParams index_params_;
RyoheiHagimoto 0:0e0631af0305 125 /** Index distance */
RyoheiHagimoto 0:0e0631af0305 126 Distance distance_;
RyoheiHagimoto 0:0e0631af0305 127
RyoheiHagimoto 0:0e0631af0305 128 };
RyoheiHagimoto 0:0e0631af0305 129
RyoheiHagimoto 0:0e0631af0305 130 }
RyoheiHagimoto 0:0e0631af0305 131
RyoheiHagimoto 0:0e0631af0305 132 #endif // OPENCV_FLANN_LINEAR_INDEX_H_