Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnTemplateMatcher.h
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnTemplateMatcher.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
13 #pragma once
14 
15 #include <list>
16 #include <vector>
17 
18 #include "Eigen/Core"
19 
20 #include "cv.h"
21 
22 using namespace std;
23 using namespace Eigen;
24 
25 // drwnTemplateMatcher ---------------------------------------------------------
32 
34  protected:
35  vector<cv::Mat> _templates;
36  vector<pair<double, double> > _templateStats;
37  cv::Size _largestTemplate;
38 
39  // buffered data (clear with reset())
40  cv::Size _imgSize;
41  vector<cv::Mat> _dftTemplates;
42  cv::Mat _dftImage;
43  cv::Mat _dftResponse;
44  cv::Mat _imgSum;
45  cv::Mat _imgSqSum;
46 
47  public:
53 
55  void clear();
57  inline bool empty() const { return _templates.empty(); }
59  inline int size() const { return (int)_templates.size(); }
61  inline int width() const { return _largestTemplate.width; }
63  inline int height() const { return _largestTemplate.height; }
64 
66  void reset();
67 
72  void addTemplate(cv::Mat& t);
74  void addTemplates(vector<cv::Mat>& t);
76  void copyTemplate(const cv::Mat& t);
78  void copyTemplates(const vector<cv::Mat>& t);
79 
84  vector<cv::Mat> responses(const cv::Mat& img, int method = CV_TM_CCORR);
86  vector<cv::Mat> responses(int method = CV_TM_CCORR);
88  cv::Mat response(const cv::Mat& img, unsigned tid, int method = CV_TM_CCORR);
90  cv::Mat response(unsigned tid, int method = CV_TM_CCORR);
91 
92  // operators
94  drwnTemplateMatcher& operator=(const drwnTemplateMatcher& tm);
96  const cv::Mat& operator[](unsigned i) const;
97 
98  protected:
100  void cacheDFTAndIntegrals(const cv::Mat& image);
101 };
int size() const
returns the number of templates
Definition: drwnTemplateMatcher.h:59
cv::Size _largestTemplate
dimensions of the largest template
Definition: drwnTemplateMatcher.h:37
int height() const
returns the height of the largest template
Definition: drwnTemplateMatcher.h:63
int width() const
returns the width of the largest template
Definition: drwnTemplateMatcher.h:61
cv::Mat _imgSqSum
buffer for integral square image
Definition: drwnTemplateMatcher.h:45
vector< pair< double, double > > _templateStats
template mean and energy
Definition: drwnTemplateMatcher.h:36
Utility class for computing multiple template matches.
Definition: drwnTemplateMatcher.h:33
vector< cv::Mat > _templates
vector of templates to match
Definition: drwnTemplateMatcher.h:35
cv::Mat _dftResponse
buffer for response image
Definition: drwnTemplateMatcher.h:43
vector< cv::Mat > _dftTemplates
buffered templates in fourier space
Definition: drwnTemplateMatcher.h:41
cv::Size _imgSize
size of image being buffered
Definition: drwnTemplateMatcher.h:40
cv::Mat _imgSum
buffer for integral image
Definition: drwnTemplateMatcher.h:44
bool empty() const
returns true if there are no templates
Definition: drwnTemplateMatcher.h:57
cv::Mat _dftImage
buffered image in fourier space
Definition: drwnTemplateMatcher.h:42