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.
46 #include "ITracker3dFilter.h"
50 class Tracker3dInputPin;
51 class Tracker3dOutputPin;
53 class Tracker3dFilter : public CBaseFilter, ITracker3dFilter, ITracker3dInternal, ISpecifyPropertyPages, IPersistStream
58 std::vector<ITracker3dCallback *> m_callbacks;
59 InputSize m_preferred_size;
62 // Camera calibration stuff
63 int m_calibrate_cameras; // 0 - not calibrating;
64 // 1 - calibrate until successful
65 // 2 - calibrate continuously
66 Cv3dTrackerCameraIntrinsics *m_camera_intrinsics;
67 CvSize m_etalon_size; // size of the checkerboard used to calibrate cameras
70 // Results of camera calibration
71 Cv3dTrackerCameraInfo *m_pCameraInfo;
73 // Results of tracking
74 std::vector<Cv3dTrackerTrackedObject> m_tracked_objects;
83 Sample(IMediaSample *, const ITracker::TrackingInfo &);
85 Sample(const Sample &s);
86 void operator=(const Sample &);
88 REFERENCE_TIME ts, te;
90 ITracker::TrackingInfo tracking_info;
92 Tracker3dInputPin *input_pin;
93 Tracker3dOutputPin *output_pin;
94 CMediaType media_type;
96 IplImage image_header1, image_header2;
97 typedef std::deque<Sample> SampleQueue;
99 unsigned long discarded_frames, total_frames;
102 void operator =(Stream &);
105 int m_end_of_stream_count; // used to determine when to pass
106 // end of stream to all output pins
108 bool m_camera_configuration_loaded;
110 Tracker3dFilter(TCHAR *name, IUnknown *unk);
113 void SetNumberOfStreams(int num_streams);
114 HRESULT ReadCameraIntrinsics(const char *filenames[]);
117 std::string CalibrationName(int i);
118 void LoadCameraConfiguration();
119 void SaveCameraConfiguration();
122 static CUnknown * WINAPI CreateInstance(IUnknown *unk, HRESULT *phr);
124 STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
127 HRESULT CheckMediaType(int pin, const CMediaType *mt);
128 HRESULT SetMediaType(int pin, const CMediaType *mt);
129 HRESULT GetMediaType(int pin, int pos, CMediaType *mt);
130 HRESULT Receive(int pin, IMediaSample *);
131 HRESULT EndOfStream(int pin);
132 HRESULT Flush(int pin);
134 // Overridden from CBaseFilter
135 CBasePin *GetPin(int n);
137 STDMETHODIMP Run(REFERENCE_TIME);
138 STDMETHODIMP Pause();
141 // ISpecifyPropertyPages interface
142 STDMETHODIMP GetPages(CAUUID *pPages);
145 STDMETHODIMP GetClassID(CLSID *clsid);
146 STDMETHODIMP IsDirty();
147 STDMETHODIMP Load(IStream *);
148 STDMETHODIMP Save(IStream *, BOOL clear_dirty);
149 STDMETHODIMP GetSizeMax(ULARGE_INTEGER *size);
152 STDMETHODIMP GetNumberOfCameras(int &num_cameras);
153 STDMETHODIMP LoadCameraConfiguration(const char *filename);
154 STDMETHODIMP SaveCameraConfiguration(const char *filename);
155 STDMETHODIMP GetDefaultTracker(GUID &filename);
156 STDMETHODIMP SetDefaultTracker(const GUID &filename);
157 STDMETHODIMP SetTrackers(int numstreams, ITracker * const *trackers);
158 STDMETHODIMP GetTrackers(std::vector<ITracker *> &trackers);
159 STDMETHODIMP CalibrateCameras(int checkerboard_width, int checkerboard_height,
160 const char *camera_intrinsics_filenames[],
163 STDMETHODIMP GetTrackedObjects(std::vector<Cv3dTrackerTrackedObject> &tracked_objects);
164 STDMETHODIMP SetViewingStream(int stream);
165 STDMETHODIMP GetViewingStream(int &stream);
166 STDMETHODIMP GetCameraName(int i, std::string &name);
167 STDMETHODIMP SetPreferredInputSize(InputSize size);
168 STDMETHODIMP GetPreferredInputSize(InputSize &size);
169 STDMETHODIMP AddCallback(ITracker3dCallback *);
170 STDMETHODIMP RemoveCallback(ITracker3dCallback *);
171 STDMETHODIMP IsConnected(bool &any_connected, bool &all_connected);
173 // ITracker3dInternal
174 STDMETHODIMP GetCameraInfo(std::vector<Cv3dTrackerCameraInfo> &info);
177 class Tracker3dInputPin : public CBaseInputPin
179 Tracker3dFilter *m_pFilter;
184 Tracker3dInputPin(int pin_number, Tracker3dFilter *filter, CCritSec *cs);
185 ~Tracker3dInputPin();
187 STDMETHODIMP_(ULONG) NonDelegatingAddRef();
188 STDMETHODIMP_(ULONG) NonDelegatingRelease();
190 HRESULT CheckMediaType(const CMediaType *mt);
191 HRESULT SetMediaType(const CMediaType *mt);
192 HRESULT GetMediaType(int pos, CMediaType *mt);
193 STDMETHODIMP GetAllocator(IMemAllocator **);
194 STDMETHODIMP NotifyAllocator(IMemAllocator *allocator, BOOL read_only);
195 STDMETHODIMP Receive(IMediaSample *sample);
196 STDMETHODIMP Notify(IBaseFilter * pSender, Quality q) { return E_NOTIMPL; };
197 STDMETHODIMP EndOfStream();
198 STDMETHODIMP BeginFlush();
199 STDMETHODIMP EndFlush();
200 STDMETHODIMP NewSegment(REFERENCE_TIME start, REFERENCE_TIME stop, double rate);
203 class Tracker3dOutputPin : public CBaseOutputPin
205 Tracker3dFilter *m_pFilter;
210 Tracker3dOutputPin(int pin_number, Tracker3dFilter *filter, CCritSec *cs);
211 ~Tracker3dOutputPin();
213 STDMETHODIMP_(ULONG) NonDelegatingAddRef();
214 STDMETHODIMP_(ULONG) NonDelegatingRelease();
216 HRESULT CheckMediaType(const CMediaType *mt);
217 HRESULT SetMediaType(const CMediaType *mt);
218 HRESULT GetMediaType(int pos, CMediaType *mt);
219 HRESULT DecideAllocator(IMemInputPin *, IMemAllocator **);
220 HRESULT DecideBufferSize(IMemAllocator *, ALLOCATOR_PROPERTIES *) { return E_NOTIMPL; };
221 STDMETHODIMP Notify(IBaseFilter * pSender, Quality q) { return E_NOTIMPL; };