Rev Author Line No. Line
178 kaklik 1 #ifndef __POINTERRECOGNITION_HH
2 #define __POINTERRECOGNITION_HH
3  
4 #include <boost/numeric/ublas/vector.hpp>
5 #include <boost/smart_ptr.hpp>
6 #include "image.h"
7 #include "cameraProjectorCalibration.hh"
8  
9 /// Class for recognising pointer.
10 class PointerRecognition
11 {
12 ///
13 public:
14 ///
15 typedef boost::numeric::ublas::vector< double > Vector;
16 /** Constructor.
17 @param _cameraProjectorCalibration Smart pointer to calibration object.
18 @param _refImg Reference image with the colours to recognise the pointer. */
19 PointerRecognition( CameraProjectorCalibrationPtr _cameraProjectorCalibration,
20 const mimas::image< mimas::rgba< unsigned char > > &_refImg );
21 /// Change reference image (and recompute colour histogram).
22 void setReferenceImage
23 ( const mimas::image< mimas::rgba< unsigned char > > &_refImg );
24 /** Perform recognition.
25 @param _frame Camera image
26 @param camPos On success the estimated pointer position in the camera
27 image.
28 @param pos On success the estimated pointer position on the screen
29 (computed using the camera calibration).
30 @return \c true if pointer was recognised */
31 bool findPointer
32 ( const mimas::image< mimas::rgba< unsigned char > > &_frame,
33 Vector &camPos, Vector &pos )
34 throw (mimas::mimasexception);
35 /** Segmented image from the last recognition step.
36 The image is stored so that it can be displayed for information. */
37 mimas::image< unsigned char > getSegmentedImage(void) const
38 { return segmentedImage; }
39 /** Set active screen area for recognition.
40 Estimated pointer coordinates outside this area will be considered
41 to be erroneous. */
42 void setClip( int _x, int _y, int _w, int _h )
43 { x =_x; y = _y; w = _w; h = _h; }
44 ///
45 void setThreshold( double _threshold ) { threshold = _threshold; }
46 ///
47 void setSigma( double _sigma );
48 ///
49 void setTrackingRange( int _trackingRange )
50 { trackingRange = _trackingRange; }
51 ///
52 int getMinX(void) { return minX; }
53 ///
54 int getMinY(void) { return minY; }
55 ///
56 int getMaxX(void) { return maxX; }
57 ///
58 int getMaxY(void) { return maxY; }
59 protected:
60 ///
61 CameraProjectorCalibrationPtr cameraProjectorCalibration;
62 /** Clipping coordinates (active screen are for recognition)
63 @see setClip
64 @name Clipping coordinates
65 @{ */
66 ///
67 int x;
68 ///
69 int y;
70 ///
71 int w;
72 ///
73 int h;
74 ///@}
75 /// Colour histogram computed from reference image.
76 boost::multi_array< int, 3 > histogram;
77 ///
78 int numPixels;
79 /// Threshold used in colour segmentation.
80 double threshold;
81 ///
82 double sigma;
83 ///
84 int minSize;
85 /** Segmented image of last recognition step.
86 @see getSegmentedImage */
87 mimas::image< unsigned char > segmentedImage;
88 ///
89 bool haveOldPos;
90 ///
91 int oldX;
92 ///
93 int oldY;
94 ///
95 int deltaX;
96 ///
97 int deltaY;
98 ///
99 int minX;
100 ///
101 int minY;
102 ///
103 int maxX;
104 ///
105 int maxY;
106 ///
107 int trackingRange;
108 };
109  
110 ///
111 typedef boost::shared_ptr< PointerRecognition > PointerRecognitionPtr;
112  
113 #endif