1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
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.
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.
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.
42 // This class implements the property page for the CCalibFilter filter
44 #pragma warning( disable: 4201 4710 )
47 #include <cvstreams.h>
51 #include "iCalibFilter.h"
52 #include "CalibFilterprop.h"
53 #include "CalibFilter.h"
54 #include "CalibFilteruids.h"
58 #include "Calib3DWindow.h"
63 // This goes in the factory template table to create new filter instances
65 const signed char MaxLevel = 127;
66 const signed char MinLevel = -128;
68 CUnknown * WINAPI CCalibFilterProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr)
70 CUnknown *punk = new CCalibFilterProperties(lpunk, phr);
82 CCalibFilterProperties::CCalibFilterProperties(LPUNKNOWN pUnk, HRESULT *phr) :
83 CBasePropertyPage(NAME("CalibFilter Property Page"),pUnk,
95 // Sets m_bDirty and notifies the property page site of the change
97 void CCalibFilterProperties::SetDirty()
100 if (m_pPageSite) m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
104 void CCalibFilterProperties::SetControls( HWND hwnd )
107 SetDlgItemInt( hwnd, IDC_WIDTH, (int)m_params.etalon_params[0], 0 );
108 SetDlgItemInt( hwnd, IDC_HEIGHT, (int)m_params.etalon_params[1], 0 );
109 sprintf(buffer,"%.2f", m_params.etalon_params[2]);
110 SetDlgItemText( hwnd, IDC_SQUARE_SIZE, buffer );
111 SetDlgItemInt( hwnd, IDC_INTERVAL, m_params.frame_interval, 0 );
112 SetDlgItemInt( hwnd, IDC_MAX_FRAMES, m_params.frames_to_collect, 0 );
114 Button_SetCheck( GetDlgItem( hwnd, IDC_UNDISTORTION), m_params.enable_undistortion != 0 );
115 Button_SetCheck( GetDlgItem( hwnd, IDC_SHOW3D), m_params.show_3d_window != 0 );
119 void CCalibFilterProperties::GetControls( HWND hwnd )
125 unsigned val = GetDlgItemInt( hwnd, IDC_WIDTH, &ok, 0 );
126 if( ok ) m_params.etalon_params[0] = (float)val;
128 val = GetDlgItemInt( hwnd, IDC_HEIGHT, &ok, 0 );
129 if( ok ) m_params.etalon_params[1] = (float)val;
131 val = GetDlgItemInt( hwnd, IDC_INTERVAL, &ok, 0 );
132 if( ok ) m_params.frame_interval = val;
134 val = GetDlgItemInt( hwnd, IDC_MAX_FRAMES, &ok, 0 );
135 if( ok ) m_params.frames_to_collect = val;
137 GetDlgItemText( hwnd, IDC_SQUARE_SIZE, buffer, sizeof(buffer));
138 if( sscanf(buffer,"%f", &fval ) == 1 )
140 m_params.etalon_params[2] = fval;
143 /////////////////////////////////
145 val = Button_GetCheck( GetDlgItem( hwnd, IDC_UNDISTORTION) );
146 m_params.enable_undistortion = val;
148 val = Button_GetCheck( GetDlgItem( hwnd, IDC_SHOW3D) );
149 m_params.show_3d_window = val;
153 void CCalibFilterProperties::SetParameters()
157 m_pCalibFilter->set_EtalonParams(
158 m_params.etalon_type,
159 m_params.etalon_params, 3 );
161 m_pCalibFilter->set_FrameInterval( m_params.frame_interval );
163 m_pCalibFilter->set_FramesToCollect( m_params.frames_to_collect );
165 m_pCalibFilter->set_EnableUndistortion( m_params.enable_undistortion );
166 m_pCalibFilter->set_Show3DWindow( m_params.show_3d_window );
167 // m_pCalibFilter->set_Show3DEtalon( m_params.show_3d_etalon );
173 void CCalibFilterProperties::GetParameters()
177 long count = sizeof(m_params.etalon_params)/sizeof(float);
179 m_pCalibFilter->get_EtalonParams(
180 &m_params.etalon_type,
181 m_params.etalon_params,
183 m_params.etalon_params_count = count;
185 m_pCalibFilter->get_FrameInterval( &m_params.frame_interval );
187 m_pCalibFilter->get_FramesToCollect( &m_params.frames_to_collect );
189 m_pCalibFilter->get_EnableUndistortion( &m_params.enable_undistortion );
190 m_pCalibFilter->get_Show3DWindow( &m_params.show_3d_window );
195 void CCalibFilterProperties::StartCalibration()
199 if( m_bDirty ) Apply();
200 m_pCalibFilter->StartCalibrate();
203 void CCalibFilterProperties::SaveCameraParams()
207 m_pCalibFilter->SaveCameraParams();
210 void CCalibFilterProperties::LoadCameraParams()
214 m_pCalibFilter->LoadCameraParams();
219 void CCalibFilterProperties::PrintStatus()
221 if( m_pCalibFilter && m_hwnd &&
222 m_pCalibFilter->GetState(
223 &m_params.calib_state, &m_params.frames_collected,
224 &m_params.frames_passed, &m_params.last_frame_time ) == NOERROR )
226 char buffer[1000] = "";
228 /* My print status */
229 switch( m_params.calib_state )
231 case CalibState_Initial:
232 case CalibState_NotCalibrated:
233 sprintf(buffer,"Camera is not calibrated");
235 case CalibState_Calibrated:
237 CvCameraParams camera;
238 m_pCalibFilter->GetCameraParams( &camera );
240 sprintf(buffer,"Camera is Calibrated\r\n"
241 "principal point: (%5.1f, %5.1f)\r\n"
242 "focal length: (%7.3f x %7.3f)\r\n"
243 "distortion: k1 = %6.3f, k2 = %6.3f\r\n"
244 "\tp1 = %6.3f, p2 = %6.3f",
245 camera.principalPoint[0], camera.principalPoint[1],
246 camera.focalLength[0], camera.focalLength[1],
247 camera.distortion[0], camera.distortion[1],
248 camera.distortion[2], camera.distortion[3] );
251 case CalibState_CalibrationProcess:
252 sprintf(buffer,"Processing... Collected %d frames",m_params.frames_collected);
257 SetDlgItemText( m_hwnd, IDC_STATUS, buffer );
264 // Virtual method called by base class with Window messages
266 BOOL CCalibFilterProperties::OnReceiveMessage(HWND hwnd,
277 SetTimer( hwnd, 0, 50, 0 );
287 if( HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_START_CALIB )
291 if( HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_SAVECALIBRATION )
295 if( HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_LOADCALIBRATION )
299 else if( HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_STOP )
303 else if( HIWORD(wParam) == EN_CHANGE || HIWORD(wParam) == BN_CLICKED )
317 KillTimer( hwnd, 0 );
321 return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
323 } // OnReceiveMessage
329 // Called when the property page connects to a filter
331 HRESULT CCalibFilterProperties::OnConnect(IUnknown *pUnknown)
333 ASSERT(m_pCalibFilter == NULL);
335 HRESULT hr = pUnknown->QueryInterface(IID_ICalibFilter, (void **) &m_pCalibFilter);
336 if( FAILED(hr) ) return E_NOINTERFACE;
338 ASSERT(m_pCalibFilter);
350 // Called when we're disconnected from a filter
352 HRESULT CCalibFilterProperties::OnDisconnect()
354 // Release of Interface after setting the parameters
355 if( !m_pCalibFilter ) return E_UNEXPECTED;
356 m_pCalibFilter->Release();
357 m_pCalibFilter = NULL;
365 // We are being deactivated
367 HRESULT CCalibFilterProperties::OnDeactivate(void)
369 //MessageBox(0,"OnDeactivate","Info",MB_OK);
377 // Changes made should be kept. Change the variable
379 HRESULT CCalibFilterProperties::OnApplyChanges()