EstervQrCode 1.1.1
Library for qr code manipulation
detection_based_tracker.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Third party copyrights are property of their respective owners.
17 //
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
20 //
21 // * Redistribution's of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
23 //
24 // * Redistribution's in binary form must reproduce the above copyright notice,
25 // this list of conditions and the following disclaimer in the documentation
26 // and/or other materials provided with the distribution.
27 //
28 // * The name of the copyright holders may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
30 //
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
41 //
42 //M*/
43 
44 #ifndef OPENCV_OBJDETECT_DBT_HPP
45 #define OPENCV_OBJDETECT_DBT_HPP
46 
47 #include <opencv2/core.hpp>
48 
49 #include <vector>
50 
51 namespace cv
52 {
53 
56 
58 {
59  public:
61  {
63  int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0
64 
66  };
67 
68  class IDetector
69  {
70  public:
72  minObjSize(96, 96),
73  maxObjSize(INT_MAX, INT_MAX),
74  minNeighbours(2),
75  scaleFactor(1.1f)
76  {}
77 
78  virtual void detect(const cv::Mat& image, std::vector<cv::Rect>& objects) = 0;
79 
81  {
82  minObjSize = min;
83  }
85  {
86  maxObjSize = max;
87  }
89  {
90  return minObjSize;
91  }
93  {
94  return maxObjSize;
95  }
97  {
98  return scaleFactor;
99  }
100  void setScaleFactor(float value)
101  {
102  scaleFactor = value;
103  }
105  {
106  return minNeighbours;
107  }
109  {
110  minNeighbours = value;
111  }
112  virtual ~IDetector() {}
113 
114  protected:
118  float scaleFactor;
119  };
120 
121  DetectionBasedTracker(cv::Ptr<IDetector> mainDetector, cv::Ptr<IDetector> trackingDetector, const Parameters& params);
123 
124  virtual bool run();
125  virtual void stop();
126  virtual void resetTracking();
127 
128  virtual void process(const cv::Mat& imageGray);
129 
130  bool setParameters(const Parameters& params);
131  const Parameters& getParameters() const;
132 
133 
136  virtual void getObjects(std::vector<Object>& result) const;
137 
139  {
143  WRONG_OBJECT
144  };
145  struct ExtObject
146  {
147  int id;
150  ExtObject(int _id, cv::Rect _location, ObjectStatus _status)
151  :id(_id), location(_location), status(_status)
152  {
153  }
154  };
156 
157 
158  virtual int addObject(const cv::Rect& location); //returns id of the new object
159 
160  protected:
161  class SeparateDetectionWork;
163  friend void* workcycleObjectDetectorFunction(void* p);
164 
166  {
171 
175 
177  };
180 
182  {
184 
186 
189  int id;
190 
191  TrackedObject(const cv::Rect& rect):numDetectedFrames(1), numFramesNotDetected(0)
192  {
193  lastPositions.push_back(rect);
194  id=getNextId();
195  }
196 
197  static int getNextId()
198  {
199  static int _id=0;
200  return _id++;
201  }
202  };
203 
206 
209 
211 
212  void updateTrackedObjects(const std::vector<cv::Rect>& detectedObjects);
215  void detectInRegion(const cv::Mat& img, const cv::Rect& r, std::vector<cv::Rect>& detectedObjectsInRegions);
216 };
217 
219 
220 } //end of cv namespace
221 
222 #endif
Definition: detection_based_tracker.hpp:69
void setMinObjectSize(const cv::Size &min)
Definition: detection_based_tracker.hpp:80
float scaleFactor
Definition: detection_based_tracker.hpp:118
cv::Size getMinObjectSize() const
Definition: detection_based_tracker.hpp:88
cv::Size maxObjSize
Definition: detection_based_tracker.hpp:116
IDetector()
Definition: detection_based_tracker.hpp:71
int minNeighbours
Definition: detection_based_tracker.hpp:117
void setScaleFactor(float value)
Definition: detection_based_tracker.hpp:100
int getMinNeighbours()
Definition: detection_based_tracker.hpp:104
virtual ~IDetector()
Definition: detection_based_tracker.hpp:112
void setMinNeighbours(int value)
Definition: detection_based_tracker.hpp:108
cv::Size getMaxObjectSize() const
Definition: detection_based_tracker.hpp:92
void setMaxObjectSize(const cv::Size &max)
Definition: detection_based_tracker.hpp:84
virtual void detect(const cv::Mat &image, std::vector< cv::Rect > &objects)=0
float getScaleFactor()
Definition: detection_based_tracker.hpp:96
cv::Size minObjSize
Definition: detection_based_tracker.hpp:115
Definition: detection_based_tracker.hpp:58
virtual void process(const cv::Mat &imageGray)
virtual void getObjects(std::vector< cv::Rect > &result) const
cv::Ptr< IDetector > cascadeForTracking
Definition: detection_based_tracker.hpp:210
cv::Rect calcTrackedObjectPositionToShow(int i) const
cv::Rect calcTrackedObjectPositionToShow(int i, ObjectStatus &status) const
const Parameters & getParameters() const
void detectInRegion(const cv::Mat &img, const cv::Rect &r, std::vector< cv::Rect > &detectedObjectsInRegions)
void updateTrackedObjects(const std::vector< cv::Rect > &detectedObjects)
virtual int addObject(const cv::Rect &location)
bool setParameters(const Parameters &params)
DetectionBasedTracker(cv::Ptr< IDetector > mainDetector, cv::Ptr< IDetector > trackingDetector, const Parameters &params)
cv::Ptr< SeparateDetectionWork > separateDetectionWork
Definition: detection_based_tracker.hpp:161
virtual void getObjects(std::vector< Object > &result) const
virtual void resetTracking()
friend void * workcycleObjectDetectorFunction(void *p)
std::vector< float > weightsPositionsSmoothing
Definition: detection_based_tracker.hpp:207
std::pair< cv::Rect, int > Object
Definition: detection_based_tracker.hpp:134
std::vector< float > weightsSizesSmoothing
Definition: detection_based_tracker.hpp:208
ObjectStatus
Definition: detection_based_tracker.hpp:139
@ DETECTED_TEMPORARY_LOST
Definition: detection_based_tracker.hpp:142
@ DETECTED
Definition: detection_based_tracker.hpp:141
@ DETECTED_NOT_SHOWN_YET
Definition: detection_based_tracker.hpp:140
InnerParameters innerParameters
Definition: detection_based_tracker.hpp:179
int numTrackedSteps
Definition: detection_based_tracker.hpp:204
std::vector< TrackedObject > trackedObjects
Definition: detection_based_tracker.hpp:205
virtual void getObjects(std::vector< ExtObject > &result) const
Parameters parameters
Definition: detection_based_tracker.hpp:178
n-dimensional dense array class
Definition: mat.hpp:812
Template class for 2D rectangles.
Definition: types.hpp:444
Template class for specifying the size of an image or rectangle.
Definition: types.hpp:335
int CvScalar value
Definition: core_c.h:720
CvRect rect
Definition: core_c.h:193
const CvArr const CvArr CvArr * result
Definition: core_c.h:1423
softfloat max(const softfloat &a, const softfloat &b)
Definition: softfloat.hpp:440
softfloat min(const softfloat &a, const softfloat &b)
Min and Max functions.
Definition: softfloat.hpp:437
#define CV_EXPORTS
Definition: cvdef.h:435
CvRect r
Definition: imgproc_c.h:984
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441
T push_back(T... args)
Definition: detection_based_tracker.hpp:146
ObjectStatus status
Definition: detection_based_tracker.hpp:149
cv::Rect location
Definition: detection_based_tracker.hpp:148
int id
Definition: detection_based_tracker.hpp:147
ExtObject(int _id, cv::Rect _location, ObjectStatus _status)
Definition: detection_based_tracker.hpp:150
Definition: detection_based_tracker.hpp:166
int numStepsToShowWithoutDetecting
Definition: detection_based_tracker.hpp:170
int numLastPositionsToTrack
Definition: detection_based_tracker.hpp:167
float coeffObjectSpeedUsingInPrediction
Definition: detection_based_tracker.hpp:174
int numStepsToWaitBeforeFirstShow
Definition: detection_based_tracker.hpp:168
float coeffObjectSizeToTrack
Definition: detection_based_tracker.hpp:173
float coeffTrackingWindowSize
Definition: detection_based_tracker.hpp:172
int numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown
Definition: detection_based_tracker.hpp:169
Definition: detection_based_tracker.hpp:61
int maxTrackLifetime
Definition: detection_based_tracker.hpp:62
int minDetectionPeriod
Definition: detection_based_tracker.hpp:63
Definition: detection_based_tracker.hpp:182
static int getNextId()
Definition: detection_based_tracker.hpp:197
int numFramesNotDetected
Definition: detection_based_tracker.hpp:188
PositionsVector lastPositions
Definition: detection_based_tracker.hpp:185
TrackedObject(const cv::Rect &rect)
Definition: detection_based_tracker.hpp:191
int numDetectedFrames
Definition: detection_based_tracker.hpp:187
std::vector< cv::Rect > PositionsVector
Definition: detection_based_tracker.hpp:183
int id
Definition: detection_based_tracker.hpp:189
Definition: cvstd_wrapper.hpp:74