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) 2002, 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 // * Redistributions of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistributions 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 // ////////////////////////////////////////////////////////////////////////////
44 // CamShiftTrackerPropertyPage
46 // This is a property page for the COM wrapper for the OpenCV CamShift tracker.
47 // This is intended as sample code only. It only supports calibration of
49 // A complete implementation would have additional controls to control the
52 // ////////////////////////////////////////////////////////////////////////////
58 #include "autorelease.h"
59 #include "ITracker3dFilter.h"
60 #include "ICamShiftTracker.h"
61 #include "CamShiftTrackerPropertyPage.h"
67 // Used by the DirectShow base classes to create instances
69 CUnknown *CamShiftTrackerPropertyPage::CreateInstance(IUnknown *outer, HRESULT *phr)
71 CUnknown *punk = new CamShiftTrackerPropertyPage(outer, phr);
82 CamShiftTrackerPropertyPage::CamShiftTrackerPropertyPage(IUnknown *outer, HRESULT *phr) :
83 CBasePropertyPage(NAME("CamShift Tracker Property Page"), outer, IDD_CamShiftTrackerPropertyPage, IDS_TITLE)
87 CamShiftTrackerPropertyPage::~CamShiftTrackerPropertyPage()
89 for (int i = 0; i < m_trackers.size(); i++)
90 SAFE_RELEASE(m_trackers[i]);
96 // Handles the messages for our property window
98 BOOL CamShiftTrackerPropertyPage::OnReceiveMessage(HWND hwnd, UINT msg, WPARAM w, LPARAM l)
100 if (msg == WM_COMMAND)
108 for (int i = 0; i < m_trackers.size(); i++)
109 m_trackers[i]->Calibrate();
116 return CBasePropertyPage::OnReceiveMessage(hwnd, msg, w, l);
122 // Called when we connect to the filter
124 HRESULT CamShiftTrackerPropertyPage::OnConnect(IUnknown *pUnknown)
126 ITracker3dFilter *tracker_filter;
128 HRESULT hr = pUnknown->QueryInterface(IID_ITracker3dFilter, (void **) &tracker_filter);
132 std::vector<ITracker *> trackers;
133 tracker_filter->GetTrackers(trackers);
134 m_trackers.resize(0);
135 m_trackers.reserve(trackers.size());
136 for (int i = 0; i < trackers.size(); i++)
138 // Ensure that we are the correct property page for each filter
139 // Ignore any that request a different page
140 GUID page = GUID_NULL;
141 trackers[i]->GetPropertyPage(&page);
142 if (page == CLSID_CamShiftTrackerPropertyPage)
145 trackers[i]->QueryInterface(IID_ICamShiftTracker, (void **)&p);
146 m_trackers.push_back(p);
148 trackers[i]->Release();
151 tracker_filter->Release();
160 // Called when we disconnect from the filter
162 HRESULT CamShiftTrackerPropertyPage::OnDisconnect()
164 for (int i = 0; i < m_trackers.size(); i++)
165 SAFE_RELEASE(m_trackers[i]);
174 // We are being activated
176 HRESULT CamShiftTrackerPropertyPage::OnActivate()
184 // We are being deactivated
186 HRESULT CamShiftTrackerPropertyPage::OnDeactivate(void)
194 // Apply any changes so far made
196 HRESULT CamShiftTrackerPropertyPage::OnApplyChanges()