Move the sources to trunk
[opencv] / filters / CalibFilter / CalibFilter.h
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 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #pragma once
43
44 #include "CV.h"
45 #include "Calib3DWindow.h"
46
47 class CCalibFilter : public CTransInPlaceFilter,
48                      public ICalibFilter,
49                      public ISpecifyPropertyPages,
50                      public CPersistStream
51 {
52
53 public:
54     
55     // Constructor
56     CCalibFilter( TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr);
57
58     // Destructor
59     ~CCalibFilter();
60
61     static CUnknown * WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);
62
63     // Reveals CCalibFilter & ISpecifyPropertyPages
64     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
65
66     DECLARE_IUNKNOWN;
67
68     HRESULT Transform(IMediaSample *pSample);
69     HRESULT CheckInputType(const CMediaType *mtIn);
70     HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);
71     HRESULT DecideBufferSize(IMemAllocator *pAlloc,ALLOCATOR_PROPERTIES *pProperties);
72     HRESULT CheckTransform(const CMediaType *mtIn,const CMediaType *mtOut);
73
74     // ICCalibFilter methods
75     STDMETHODIMP get_EtalonParams(
76         CalibEtalonType*   etalon_type,
77         float*  etalon_params,
78         long*   etalon_param_count);
79
80     STDMETHODIMP set_EtalonParams(
81         CalibEtalonType    etalon_type,
82         float*  etalon_params,
83         long    etalon_param_count);
84     
85     STDMETHODIMP get_FrameInterval(
86         long*   count);
87
88     STDMETHODIMP set_FrameInterval(
89         long    count);
90
91     STDMETHODIMP get_FramesToCollect(
92         long*   frames);
93
94     STDMETHODIMP set_FramesToCollect(
95         long    frames);
96
97     STDMETHODIMP StartCalibrate();
98
99 ////////////////////////////////
100
101     STDMETHODIMP get_EnableFilter(
102         long*   enable);
103
104     STDMETHODIMP set_EnableFilter(
105         long    enable);
106
107     STDMETHODIMP get_EnableUndistortion(
108         long*   enable);
109
110     STDMETHODIMP set_EnableUndistortion(
111         long    enable);
112
113     STDMETHODIMP get_Show3DWindow(
114         long*   enable);
115
116     STDMETHODIMP set_Show3DWindow(
117         long    enable);
118
119     STDMETHODIMP get_TrackEtalon(
120         long*   enable);
121
122     STDMETHODIMP set_TrackEtalon(
123         long    enable);
124
125     STDMETHODIMP Update3DWindow();
126
127     STDMETHODIMP SaveCameraParams();
128
129     STDMETHODIMP LoadCameraParams();
130
131 ////////////////////////////////
132
133     STDMETHODIMP GetCameraParams( CvCameraParams* camera );
134
135     STDMETHODIMP GetState(
136        CalibState*   calib_state,
137        long*   frames_collected,
138        long*   frames_passed,
139        double* last_frame_time);
140
141     // ISpecifyPropertyPages method
142     STDMETHODIMP GetPages(CAUUID *pPages);
143
144     // IPersistStream implementation
145     STDMETHODIMP GetClassID( CLSID *pClsID );
146     int          SizeMax();
147     DWORD        GetSoftwareVersion();
148     //STDMETHODIMP Save(LPSTREAM pStm, BOOL fClearDirty);
149
150     HRESULT      ReadFromStream( IStream* stream );
151     HRESULT      WriteToStream( IStream* stream );
152
153 private:
154
155     void   CheckReallocBuffers( IplImage* rgb_img );
156     void   ProcessFrame( IplImage* rgb_img, double frame_time );
157     void   CalculateCameraParams( CvSize img_size );
158     double GetFrameTime( IMediaSample* sample );
159     void   DrawEtalon( IplImage* rgb_img, CvPoint2D32f* corners,
160                        int corner_count, CvSize etalon_size,
161                        int draw_ordered );
162     void   FillEtalonObjPoints( CvPoint3D32f* obj_points,
163                                 CvSize etalon_size,
164                                 float square_size );
165
166     CvSize GetEtalonSize();
167     
168     // Non interface locking critical section
169     CCritSec  m_CCalibFilterLock;
170     CalibFilterParams  m_params, m_initial_params;
171
172     /* temporary images, used in processing */
173     IplImage*         m_gray_img;
174     IplImage*         m_thresh_img;
175     IplImage*         m_undist_img;
176
177     /* processed frame */
178     IplImage*         m_rgb_img;
179     
180     /* calibration buffers */
181     int                m_max_points;
182     CvPoint2D32f*      m_imagePoints;
183     CvPoint3D32f*      m_objectPoints;
184     CvPoint3D32f*      m_transVects;
185     float*             m_rotMatrs;
186     int*               m_numsPoints;
187     HANDLE             m_thread;
188     
189     /* camera parameters */
190     CvCameraParams   m_camera;
191
192     /* 3D OpenGL window */
193     CCalib3DWindow*    m_window3D;
194
195     /* undistortion data */
196     CvCameraParams   m_undistort_params;
197     IplImage*        m_undistort_data;
198
199 }; /* CCalibFilter */
200
201 /* End of file. */
202