Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LEDDetector.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __LEDDETECTOR_HH__
26 #define __LEDDETECTOR_HH__
27 
28 #include <bias_config.h>
29 
30 #ifndef BIAS_HAVE_OPENCV
31 # error Please recompile BIAS with USE_OPENCV to use this code.
32 #endif
33 
34 #include <Base/Common/W32Compat.hh>
35 #include <Base/Image/Image.hh>
36 #include <Base/Math/Vector3.hh>
37 #include <cv.h>
38 #include <vector>
39 
40 namespace BIAS
41 {
42  /**
43  @class LEDDetector
44  @brief This class contains methods to detect (IR)-LED-Spots,
45  with template matching (new search) or in "recycling" mode
46  (search at old positions).
47  @ingroup g_feature
48  @author haase 3/2007, reworked by esquivel 11/2013
49  */
50  class BIASFeatureDetector_EXPORT LEDDetector
51  {
52 
53  public:
54 
55  LEDDetector();
56 
57  ~LEDDetector();
58 
59  /**
60  @brief Detect LED spots in image.
61  @param[in] image RGB or gray image to detect LED spots in.
62  @param[in/out] results Returns LED spot positions in current image.
63  Parameters of 3d vectors are (x, y, val) where val is brightness.
64  Can be also used as input parameter to specify LED spots positions
65  in last image to use "recycling" mode.
66  @return Returns <0 in case of errors, >= 0 otherwise.
67  */
68  int Compute(const BIAS::Image<unsigned char> &image,
69  std::vector<BIAS::Vector3<double> > &results);
70 
71  /**
72  @brief Return attributes of detected LED spots.
73  @param[out] minX Returns min. x coordinate for each detected LED spot
74  @param[out] maxX Returns max. x coordinate for each detected LED spot
75  @param[out] maxValues Returns max. gray value for each detected LED spot
76  */
77  void GetAttributes(std::vector<double> &minX, std::vector<double> &maxX,
78  std::vector<double> &maxValues);
79 
80  /**
81  @brief Return neighbours of detected LED spots.
82  @param[out] neighbours Returns vector of neighbour positions for each
83  detected LED spot
84  */
85  void GetNeighbours(std::vector<std::vector<BIAS::Vector3<double> > > &neighbours);
86 
87  protected:
88 
89  int CheckNeighboursIfWhite_(int x, int y, int& a, int& b);
90 
91  int CheckNeighboursIfWhite_inter_(int x, int y);
92 
93  void Search_(int x, int y);
94 
95  int Recycle_();
96 
97  void TemplateMatching_();
98 
99  int CheckNeighbours_(int a, int b);
100 
101  IplImage *gray_threshold, *gray_orig;
102  unsigned char *data;
103 
104  std::vector<BIAS::Vector3<double> > resultpixel;
105  std::vector<BIAS::Vector3<double> > resultpixel_old;
106  std::vector<BIAS::Vector3<double> > whitepixel;
107 
108  std::vector<double> minxcoords, maxxcoords, maxvalues;
109  std::vector<std::vector<BIAS::Vector3<double> > > nextpixel;
110 
111  // lookup matrix (0 = black, 255 = white, 127 = undecided)
112  unsigned char *lookup;
114 
115  int step;
116  int width, height;
117  double mean;
118  double maxvalue;
119  double count;
123  double blobsize;
124  double valuesum;
125  double minx, maxx;
126  double blobs;
127 
128  };
129 
130 }
131 
132 #endif // __LEDDetector_hh__
std::vector< BIAS::Vector3< double > > resultpixel_old
Definition: LEDDetector.hh:105
std::vector< double > minxcoords
Definition: LEDDetector.hh:108
unsigned char * lookup
Definition: LEDDetector.hh:112
This class contains methods to detect (IR)-LED-Spots, with template matching (new search) or in &quot;recy...
Definition: LEDDetector.hh:50
std::vector< BIAS::Vector3< double > > resultpixel
Definition: LEDDetector.hh:104
double pixelweightvaluex
Definition: LEDDetector.hh:120
double pixelweightvaluey
Definition: LEDDetector.hh:121
unsigned char * data
Definition: LEDDetector.hh:102
std::vector< std::vector< BIAS::Vector3< double > > > nextpixel
Definition: LEDDetector.hh:109
std::vector< BIAS::Vector3< double > > whitepixel
Definition: LEDDetector.hh:106
IplImage * gray_threshold
Definition: LEDDetector.hh:101