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_OBJDETECT_DBT_HPP
RyoheiHagimoto 0:0e0631af0305 45 #define OPENCV_OBJDETECT_DBT_HPP
RyoheiHagimoto 0:0e0631af0305 46
RyoheiHagimoto 0:0e0631af0305 47 // After this condition removal update blacklist for bindings: modules/python/common.cmake
RyoheiHagimoto 0:0e0631af0305 48 #if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(__ANDROID__) || \
RyoheiHagimoto 0:0e0631af0305 49 (defined(__cplusplus) && __cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1700)
RyoheiHagimoto 0:0e0631af0305 50
RyoheiHagimoto 0:0e0631af0305 51 #include <vector>
RyoheiHagimoto 0:0e0631af0305 52
RyoheiHagimoto 0:0e0631af0305 53 namespace cv
RyoheiHagimoto 0:0e0631af0305 54 {
RyoheiHagimoto 0:0e0631af0305 55
RyoheiHagimoto 0:0e0631af0305 56 //! @addtogroup objdetect
RyoheiHagimoto 0:0e0631af0305 57 //! @{
RyoheiHagimoto 0:0e0631af0305 58
RyoheiHagimoto 0:0e0631af0305 59 class CV_EXPORTS DetectionBasedTracker
RyoheiHagimoto 0:0e0631af0305 60 {
RyoheiHagimoto 0:0e0631af0305 61 public:
RyoheiHagimoto 0:0e0631af0305 62 struct CV_EXPORTS Parameters
RyoheiHagimoto 0:0e0631af0305 63 {
RyoheiHagimoto 0:0e0631af0305 64 int maxTrackLifetime;
RyoheiHagimoto 0:0e0631af0305 65 int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0
RyoheiHagimoto 0:0e0631af0305 66
RyoheiHagimoto 0:0e0631af0305 67 Parameters();
RyoheiHagimoto 0:0e0631af0305 68 };
RyoheiHagimoto 0:0e0631af0305 69
RyoheiHagimoto 0:0e0631af0305 70 class IDetector
RyoheiHagimoto 0:0e0631af0305 71 {
RyoheiHagimoto 0:0e0631af0305 72 public:
RyoheiHagimoto 0:0e0631af0305 73 IDetector():
RyoheiHagimoto 0:0e0631af0305 74 minObjSize(96, 96),
RyoheiHagimoto 0:0e0631af0305 75 maxObjSize(INT_MAX, INT_MAX),
RyoheiHagimoto 0:0e0631af0305 76 minNeighbours(2),
RyoheiHagimoto 0:0e0631af0305 77 scaleFactor(1.1f)
RyoheiHagimoto 0:0e0631af0305 78 {}
RyoheiHagimoto 0:0e0631af0305 79
RyoheiHagimoto 0:0e0631af0305 80 virtual void detect(const cv::Mat& image, std::vector<cv::Rect>& objects) = 0;
RyoheiHagimoto 0:0e0631af0305 81
RyoheiHagimoto 0:0e0631af0305 82 void setMinObjectSize(const cv::Size& min)
RyoheiHagimoto 0:0e0631af0305 83 {
RyoheiHagimoto 0:0e0631af0305 84 minObjSize = min;
RyoheiHagimoto 0:0e0631af0305 85 }
RyoheiHagimoto 0:0e0631af0305 86 void setMaxObjectSize(const cv::Size& max)
RyoheiHagimoto 0:0e0631af0305 87 {
RyoheiHagimoto 0:0e0631af0305 88 maxObjSize = max;
RyoheiHagimoto 0:0e0631af0305 89 }
RyoheiHagimoto 0:0e0631af0305 90 cv::Size getMinObjectSize() const
RyoheiHagimoto 0:0e0631af0305 91 {
RyoheiHagimoto 0:0e0631af0305 92 return minObjSize;
RyoheiHagimoto 0:0e0631af0305 93 }
RyoheiHagimoto 0:0e0631af0305 94 cv::Size getMaxObjectSize() const
RyoheiHagimoto 0:0e0631af0305 95 {
RyoheiHagimoto 0:0e0631af0305 96 return maxObjSize;
RyoheiHagimoto 0:0e0631af0305 97 }
RyoheiHagimoto 0:0e0631af0305 98 float getScaleFactor()
RyoheiHagimoto 0:0e0631af0305 99 {
RyoheiHagimoto 0:0e0631af0305 100 return scaleFactor;
RyoheiHagimoto 0:0e0631af0305 101 }
RyoheiHagimoto 0:0e0631af0305 102 void setScaleFactor(float value)
RyoheiHagimoto 0:0e0631af0305 103 {
RyoheiHagimoto 0:0e0631af0305 104 scaleFactor = value;
RyoheiHagimoto 0:0e0631af0305 105 }
RyoheiHagimoto 0:0e0631af0305 106 int getMinNeighbours()
RyoheiHagimoto 0:0e0631af0305 107 {
RyoheiHagimoto 0:0e0631af0305 108 return minNeighbours;
RyoheiHagimoto 0:0e0631af0305 109 }
RyoheiHagimoto 0:0e0631af0305 110 void setMinNeighbours(int value)
RyoheiHagimoto 0:0e0631af0305 111 {
RyoheiHagimoto 0:0e0631af0305 112 minNeighbours = value;
RyoheiHagimoto 0:0e0631af0305 113 }
RyoheiHagimoto 0:0e0631af0305 114 virtual ~IDetector() {}
RyoheiHagimoto 0:0e0631af0305 115
RyoheiHagimoto 0:0e0631af0305 116 protected:
RyoheiHagimoto 0:0e0631af0305 117 cv::Size minObjSize;
RyoheiHagimoto 0:0e0631af0305 118 cv::Size maxObjSize;
RyoheiHagimoto 0:0e0631af0305 119 int minNeighbours;
RyoheiHagimoto 0:0e0631af0305 120 float scaleFactor;
RyoheiHagimoto 0:0e0631af0305 121 };
RyoheiHagimoto 0:0e0631af0305 122
RyoheiHagimoto 0:0e0631af0305 123 DetectionBasedTracker(cv::Ptr<IDetector> mainDetector, cv::Ptr<IDetector> trackingDetector, const Parameters& params);
RyoheiHagimoto 0:0e0631af0305 124 virtual ~DetectionBasedTracker();
RyoheiHagimoto 0:0e0631af0305 125
RyoheiHagimoto 0:0e0631af0305 126 virtual bool run();
RyoheiHagimoto 0:0e0631af0305 127 virtual void stop();
RyoheiHagimoto 0:0e0631af0305 128 virtual void resetTracking();
RyoheiHagimoto 0:0e0631af0305 129
RyoheiHagimoto 0:0e0631af0305 130 virtual void process(const cv::Mat& imageGray);
RyoheiHagimoto 0:0e0631af0305 131
RyoheiHagimoto 0:0e0631af0305 132 bool setParameters(const Parameters& params);
RyoheiHagimoto 0:0e0631af0305 133 const Parameters& getParameters() const;
RyoheiHagimoto 0:0e0631af0305 134
RyoheiHagimoto 0:0e0631af0305 135
RyoheiHagimoto 0:0e0631af0305 136 typedef std::pair<cv::Rect, int> Object;
RyoheiHagimoto 0:0e0631af0305 137 virtual void getObjects(std::vector<cv::Rect>& result) const;
RyoheiHagimoto 0:0e0631af0305 138 virtual void getObjects(std::vector<Object>& result) const;
RyoheiHagimoto 0:0e0631af0305 139
RyoheiHagimoto 0:0e0631af0305 140 enum ObjectStatus
RyoheiHagimoto 0:0e0631af0305 141 {
RyoheiHagimoto 0:0e0631af0305 142 DETECTED_NOT_SHOWN_YET,
RyoheiHagimoto 0:0e0631af0305 143 DETECTED,
RyoheiHagimoto 0:0e0631af0305 144 DETECTED_TEMPORARY_LOST,
RyoheiHagimoto 0:0e0631af0305 145 WRONG_OBJECT
RyoheiHagimoto 0:0e0631af0305 146 };
RyoheiHagimoto 0:0e0631af0305 147 struct ExtObject
RyoheiHagimoto 0:0e0631af0305 148 {
RyoheiHagimoto 0:0e0631af0305 149 int id;
RyoheiHagimoto 0:0e0631af0305 150 cv::Rect location;
RyoheiHagimoto 0:0e0631af0305 151 ObjectStatus status;
RyoheiHagimoto 0:0e0631af0305 152 ExtObject(int _id, cv::Rect _location, ObjectStatus _status)
RyoheiHagimoto 0:0e0631af0305 153 :id(_id), location(_location), status(_status)
RyoheiHagimoto 0:0e0631af0305 154 {
RyoheiHagimoto 0:0e0631af0305 155 }
RyoheiHagimoto 0:0e0631af0305 156 };
RyoheiHagimoto 0:0e0631af0305 157 virtual void getObjects(std::vector<ExtObject>& result) const;
RyoheiHagimoto 0:0e0631af0305 158
RyoheiHagimoto 0:0e0631af0305 159
RyoheiHagimoto 0:0e0631af0305 160 virtual int addObject(const cv::Rect& location); //returns id of the new object
RyoheiHagimoto 0:0e0631af0305 161
RyoheiHagimoto 0:0e0631af0305 162 protected:
RyoheiHagimoto 0:0e0631af0305 163 class SeparateDetectionWork;
RyoheiHagimoto 0:0e0631af0305 164 cv::Ptr<SeparateDetectionWork> separateDetectionWork;
RyoheiHagimoto 0:0e0631af0305 165 friend void* workcycleObjectDetectorFunction(void* p);
RyoheiHagimoto 0:0e0631af0305 166
RyoheiHagimoto 0:0e0631af0305 167 struct InnerParameters
RyoheiHagimoto 0:0e0631af0305 168 {
RyoheiHagimoto 0:0e0631af0305 169 int numLastPositionsToTrack;
RyoheiHagimoto 0:0e0631af0305 170 int numStepsToWaitBeforeFirstShow;
RyoheiHagimoto 0:0e0631af0305 171 int numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown;
RyoheiHagimoto 0:0e0631af0305 172 int numStepsToShowWithoutDetecting;
RyoheiHagimoto 0:0e0631af0305 173
RyoheiHagimoto 0:0e0631af0305 174 float coeffTrackingWindowSize;
RyoheiHagimoto 0:0e0631af0305 175 float coeffObjectSizeToTrack;
RyoheiHagimoto 0:0e0631af0305 176 float coeffObjectSpeedUsingInPrediction;
RyoheiHagimoto 0:0e0631af0305 177
RyoheiHagimoto 0:0e0631af0305 178 InnerParameters();
RyoheiHagimoto 0:0e0631af0305 179 };
RyoheiHagimoto 0:0e0631af0305 180 Parameters parameters;
RyoheiHagimoto 0:0e0631af0305 181 InnerParameters innerParameters;
RyoheiHagimoto 0:0e0631af0305 182
RyoheiHagimoto 0:0e0631af0305 183 struct TrackedObject
RyoheiHagimoto 0:0e0631af0305 184 {
RyoheiHagimoto 0:0e0631af0305 185 typedef std::vector<cv::Rect> PositionsVector;
RyoheiHagimoto 0:0e0631af0305 186
RyoheiHagimoto 0:0e0631af0305 187 PositionsVector lastPositions;
RyoheiHagimoto 0:0e0631af0305 188
RyoheiHagimoto 0:0e0631af0305 189 int numDetectedFrames;
RyoheiHagimoto 0:0e0631af0305 190 int numFramesNotDetected;
RyoheiHagimoto 0:0e0631af0305 191 int id;
RyoheiHagimoto 0:0e0631af0305 192
RyoheiHagimoto 0:0e0631af0305 193 TrackedObject(const cv::Rect& rect):numDetectedFrames(1), numFramesNotDetected(0)
RyoheiHagimoto 0:0e0631af0305 194 {
RyoheiHagimoto 0:0e0631af0305 195 lastPositions.push_back(rect);
RyoheiHagimoto 0:0e0631af0305 196 id=getNextId();
RyoheiHagimoto 0:0e0631af0305 197 };
RyoheiHagimoto 0:0e0631af0305 198
RyoheiHagimoto 0:0e0631af0305 199 static int getNextId()
RyoheiHagimoto 0:0e0631af0305 200 {
RyoheiHagimoto 0:0e0631af0305 201 static int _id=0;
RyoheiHagimoto 0:0e0631af0305 202 return _id++;
RyoheiHagimoto 0:0e0631af0305 203 }
RyoheiHagimoto 0:0e0631af0305 204 };
RyoheiHagimoto 0:0e0631af0305 205
RyoheiHagimoto 0:0e0631af0305 206 int numTrackedSteps;
RyoheiHagimoto 0:0e0631af0305 207 std::vector<TrackedObject> trackedObjects;
RyoheiHagimoto 0:0e0631af0305 208
RyoheiHagimoto 0:0e0631af0305 209 std::vector<float> weightsPositionsSmoothing;
RyoheiHagimoto 0:0e0631af0305 210 std::vector<float> weightsSizesSmoothing;
RyoheiHagimoto 0:0e0631af0305 211
RyoheiHagimoto 0:0e0631af0305 212 cv::Ptr<IDetector> cascadeForTracking;
RyoheiHagimoto 0:0e0631af0305 213
RyoheiHagimoto 0:0e0631af0305 214 void updateTrackedObjects(const std::vector<cv::Rect>& detectedObjects);
RyoheiHagimoto 0:0e0631af0305 215 cv::Rect calcTrackedObjectPositionToShow(int i) const;
RyoheiHagimoto 0:0e0631af0305 216 cv::Rect calcTrackedObjectPositionToShow(int i, ObjectStatus& status) const;
RyoheiHagimoto 0:0e0631af0305 217 void detectInRegion(const cv::Mat& img, const cv::Rect& r, std::vector<cv::Rect>& detectedObjectsInRegions);
RyoheiHagimoto 0:0e0631af0305 218 };
RyoheiHagimoto 0:0e0631af0305 219
RyoheiHagimoto 0:0e0631af0305 220 //! @} objdetect
RyoheiHagimoto 0:0e0631af0305 221
RyoheiHagimoto 0:0e0631af0305 222 } //end of cv namespace
RyoheiHagimoto 0:0e0631af0305 223 #endif
RyoheiHagimoto 0:0e0631af0305 224
RyoheiHagimoto 0:0e0631af0305 225 #endif