The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPFaceDetectorFilter Class Reference

#include <MPFaceDetectorFilter.h>

Collaboration diagram for MPFaceDetectorFilter:

Collaboration graph
[legend]
List of all members.

Public Member Functions

HRESULT CheckInputType (const CMediaType *mtIn)
HRESULT CheckTransform (const CMediaType *mtIn, const CMediaType *mtOut)
HRESULT DecideBufferSize (IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pProperties)
STDMETHODIMP GetClassID (CLSID *pClsid)
HRESULT GetMediaType (int iPosition, CMediaType *pMediaType)
STDMETHODIMP NonDelegatingQueryInterface (REFIID riid, void **ppv)
HRESULT ReadFromStream (IStream *pStream)
HRESULT ScribbleToStream (IStream *pStream)
virtual HRESULT StartStreaming ()
virtual HRESULT StopStreaming ()
HRESULT Transform (IMediaSample *pIn, IMediaSample *pOut)

Static Public Member Functions

CUnknown *WINAPI CreateInstance (LPUNKNOWN punk, HRESULT *phr)

Public Attributes

 DECLARE_IUNKNOWN

Private Member Functions

BOOL CanPerformMPFaceDetectorFilter (const CMediaType *pMediaType) const
HRESULT Copy (IMediaSample *pSource, IMediaSample *pDest)
 MPFaceDetectorFilter (TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr)
HRESULT Transform (IMediaSample *pMediaSample)
 ~MPFaceDetectorFilter ()

Private Attributes

CRefTime m_currentTime
int m_effect
int m_imgHeight
int m_imgWidth
FilterInterface m_interface
CRefTime m_lastValidTime
const long m_lBufferRequest
CCritSec m_MPFaceDetectorFilterLock
CRefTime m_resetInterval

Constructor & Destructor Documentation

MPFaceDetectorFilter TCHAR *  tszName,
LPUNKNOWN  punk,
HRESULT *  phr
[private]
 

Definition at line 110 of file MPFaceDetectorFilter.cpp.

Referenced by CreateInstance().

00112 : CTransformFilter(tszName, punk, CLSID_MPISearchAdaFilter)
00113 #else
00114 : CTransformFilter(tszName, punk, CLSID_MPISearchFilter)
00115 #endif
00116 , m_effect(IDC_RED)
00117 , m_lBufferRequest(1)
00118 , CPersistStream(punk, phr)
00119 {
00120         char sz[60];
00121         GetProfileStringA("Adaptability", "ResetInterval", "30.0", sz, 60);
00122         m_resetInterval = COARefTime(atof(sz));
00123         
00124         m_currentTime = COARefTime(0.0);     
00125         m_lastValidTime = COARefTime(0.0);
00126         
00128         
00129         srand( (unsigned)time( NULL ) );
00130 
00131 } // (Constructor)

~MPFaceDetectorFilter  )  [private]
 

Definition at line 484 of file MPFaceDetectorFilter.cpp.

00484 {}


Member Function Documentation

BOOL CanPerformMPFaceDetectorFilter const CMediaType *  pMediaType  )  const [private]
 

Definition at line 423 of file MPFaceDetectorFilter.cpp.

References BOOL.

Referenced by CheckInputType(), and CheckTransform().

00424 {
00425         if (IsEqualGUID(*pMediaType->Type(), MEDIATYPE_Video)) {
00426                 if (IsEqualGUID(*pMediaType->Subtype(), MEDIASUBTYPE_RGB24)) {
00427                         VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *) pMediaType->Format();
00428                         return (pvi->bmiHeader.biBitCount == 24);
00429                 } 
00430         }
00431         return FALSE;
00432 } // CanPerformMPFaceDetectorFilter

HRESULT CheckInputType const CMediaType *  mtIn  ) 
 

Definition at line 332 of file MPFaceDetectorFilter.cpp.

References CanPerformMPFaceDetectorFilter().

00333 {
00334         // check this is a VIDEOINFOHEADER type
00335         if (*mtIn->FormatType() != FORMAT_VideoInfo)
00336                 return E_INVALIDARG;
00337         // Can we transform this type
00338         if (CanPerformMPFaceDetectorFilter(mtIn)) 
00339                 return NOERROR;
00340         return E_FAIL;
00341 }

Here is the call graph for this function:

HRESULT CheckTransform const CMediaType *  mtIn,
const CMediaType *  mtOut
 

Definition at line 350 of file MPFaceDetectorFilter.cpp.

References CanPerformMPFaceDetectorFilter().

00351 {
00352         if (CanPerformMPFaceDetectorFilter(mtIn)) {
00353                 if (*mtIn == *mtOut)
00354                         return NOERROR;   
00355         }
00356         return E_FAIL;
00357 } // CheckTransform

Here is the call graph for this function:

HRESULT Copy IMediaSample *  pSource,
IMediaSample *  pDest
[private]
 

Definition at line 210 of file MPFaceDetectorFilter.cpp.

References ASSERT, BYTE, FALSE, LONGLONG, m_imgHeight, m_imgWidth, m_interface, FilterInterface::printFrame(), RGBTRIPLE, and TRUE.

Referenced by Transform().

00211 {
00212         // Copy the sample data
00213         
00214         BYTE *pSourceBuffer, *pDestBuffer;
00215         long lSourceSize = pSource->GetActualDataLength();
00216         long lDestSize  = pDest->GetSize();
00217         
00218         ASSERT(lDestSize >= lSourceSize);
00219         
00220         pSource->GetPointer(&pSourceBuffer);
00221         pDest->GetPointer(&pDestBuffer);
00222         
00223         m_interface.printFrame((RGBTRIPLE*)pSourceBuffer, m_imgWidth, m_imgHeight);
00224         CopyMemory( (PVOID) pDestBuffer,(PVOID) pSourceBuffer,lSourceSize);
00225         
00226         // Copy the sample times
00227         
00228         REFERENCE_TIME TimeStart, TimeEnd;
00229         if (NOERROR == pSource->GetTime(&TimeStart, &TimeEnd)) {
00230                 pDest->SetTime(&TimeStart, &TimeEnd);
00231         }
00232         
00233         LONGLONG MediaStart, MediaEnd;
00234         if (pSource->GetMediaTime(&MediaStart,&MediaEnd) == NOERROR) {
00235                 pDest->SetMediaTime(&MediaStart,&MediaEnd);
00236         }
00237         
00238         // Copy the Sync point property
00239         
00240         HRESULT hr = pSource->IsSyncPoint();
00241         if (hr == S_OK) {
00242                 pDest->SetSyncPoint(TRUE);
00243         }
00244         else if (hr == S_FALSE) {
00245                 pDest->SetSyncPoint(FALSE);
00246         }
00247         else {  // an unexpected error has occured...
00248                 return E_UNEXPECTED;
00249         }
00250         
00251         // Copy the media type
00252         
00253         AM_MEDIA_TYPE *pMediaType;
00254         pSource->GetMediaType(&pMediaType);
00255         pDest->SetMediaType(pMediaType);
00256         DeleteMediaType(pMediaType);
00257         
00258         // Copy the preroll property
00259         
00260         hr = pSource->IsPreroll();
00261         if (hr == S_OK) {
00262                 pDest->SetPreroll(TRUE);
00263         }
00264         else if (hr == S_FALSE) {
00265                 pDest->SetPreroll(FALSE);
00266         }
00267         else {  // an unexpected error has occured...
00268                 return E_UNEXPECTED;
00269         }
00270         
00271         // Copy the discontinuity property
00272         hr = pSource->IsDiscontinuity();
00273         
00274         if (hr == S_OK)
00275                 pDest->SetDiscontinuity(TRUE);
00276         
00277         else if (hr == S_FALSE)
00278                 pDest->SetDiscontinuity(FALSE);
00279         
00280         else 
00281                 return E_UNEXPECTED; // an unexpected error has occured...
00282         
00283         // Copy the actual data length
00284         long lDataLength = pSource->GetActualDataLength();
00285         pDest->SetActualDataLength(lDataLength);
00286         
00287         return NOERROR;
00288 } // Copy

Here is the call graph for this function:

CUnknown * CreateInstance LPUNKNOWN  punk,
HRESULT *  phr
[static]
 

Definition at line 140 of file MPFaceDetectorFilter.cpp.

References MPFaceDetectorFilter().

00141 {
00142         MPFaceDetectorFilter *pNewObject = new MPFaceDetectorFilter(NAME("Face Detector MPLab"), punk, phr);
00143         if (pNewObject == NULL)
00144                 *phr = E_OUTOFMEMORY;
00145         return pNewObject;
00146 } // CreateInstance

Here is the call graph for this function:

HRESULT DecideBufferSize IMemAllocator *  pAlloc,
ALLOCATOR_PROPERTIES *  pProperties
 

Definition at line 367 of file MPFaceDetectorFilter.cpp.

References ASSERT.

00368 {
00369         // Is the input pin connected
00370         if (m_pInput->IsConnected() == FALSE)
00371                 return E_UNEXPECTED;
00372         ASSERT(pAlloc);
00373         ASSERT(pProperties);
00374         HRESULT hr = NOERROR;
00375         pProperties->cBuffers = 1;
00376         pProperties->cbBuffer = m_pInput->CurrentMediaType().GetSampleSize();
00377         ASSERT(pProperties->cbBuffer);
00378         // Ask the allocator to reserve us some sample memory, NOTE the function
00379         // can succeed (that is return NOERROR) but still not have allocated the
00380         // memory that we requested, so we must check we got whatever we wanted
00381         ALLOCATOR_PROPERTIES Actual;
00382         hr = pAlloc->SetProperties(pProperties,&Actual);
00383         if (FAILED(hr))
00384                 return hr;
00385         ASSERT( Actual.cBuffers == 1 );
00386         if (pProperties->cBuffers > Actual.cBuffers ||
00387                 pProperties->cbBuffer > Actual.cbBuffer) {
00388                 return E_FAIL;  
00389         }
00390         return NOERROR;
00391 } // DecideBufferSize

STDMETHODIMP GetClassID CLSID *  pClsid  ) 
 

Definition at line 449 of file MPFaceDetectorFilter.cpp.

00450 {
00451         return CBaseFilter::GetClassID(pClsid);
00452 } // GetClassID

HRESULT GetMediaType int  iPosition,
CMediaType *  pMediaType
 

Definition at line 401 of file MPFaceDetectorFilter.cpp.

00402 {
00403         // Is the input pin connected
00404         if (m_pInput->IsConnected() == FALSE) 
00405                 return E_UNEXPECTED;
00406         // This should never happen
00407         if (iPosition < 0) 
00408                 return E_INVALIDARG;
00409         // Do we have more items to offer
00410         if (iPosition > 0)
00411                 return VFW_S_NO_MORE_ITEMS;
00412         *pMediaType = m_pInput->CurrentMediaType();
00413         return NOERROR;
00414 } // GetMediaType

STDMETHODIMP NonDelegatingQueryInterface REFIID  riid,
void **  ppv
 

Definition at line 155 of file MPFaceDetectorFilter.cpp.

00156 {
00157         CheckPointer(ppv,E_POINTER);
00158         return CTransformFilter::NonDelegatingQueryInterface(riid, ppv);
00159 } // NonDelegatingQueryInterface

HRESULT ReadFromStream IStream *  pStream  ) 
 

Definition at line 475 of file MPFaceDetectorFilter.cpp.

References m_effect, and READIN.

00476 {
00477         HRESULT hr;
00478         READIN(m_effect);
00479         return NOERROR;
00480 } // ReadFromStream

HRESULT ScribbleToStream IStream *  pStream  ) 
 

Definition at line 461 of file MPFaceDetectorFilter.cpp.

References m_effect, and WRITEOUT.

00462 {
00463         HRESULT hr;
00464         WRITEOUT(m_effect);
00465         return NOERROR;
00466 } // ScribbleToStream

HRESULT StartStreaming  )  [virtual]
 

Definition at line 163 of file MPFaceDetectorFilter.cpp.

00163                                             {
00164         return S_OK;
00165 }

HRESULT StopStreaming  )  [virtual]
 

Definition at line 169 of file MPFaceDetectorFilter.cpp.

00169                                            {
00170         return S_OK;
00171 }

HRESULT Transform IMediaSample *  pMediaSample  )  [private]
 

Definition at line 293 of file MPFaceDetectorFilter.cpp.

References BYTE, fclose(), fid, fprintf(), m_currentTime, m_imgHeight, m_imgWidth, m_interface, m_lastValidTime, and FilterInterface::runInterface().

00294 {
00295         AM_MEDIA_TYPE* pType = &m_pInput->CurrentMediaType();
00296         VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *) pType->pbFormat;
00297         
00298         BYTE *pData;                // Pointer to the actual image buffer
00299         pMediaSample->GetPointer(&pData);
00300 
00301         // Get the image properties from the BITMAPINFOHEADER
00302         m_imgWidth = pvi->bmiHeader.biWidth;
00303         m_imgHeight = pvi->bmiHeader.biHeight;
00304 
00305         m_interface.runInterface(pData, m_imgWidth, m_imgHeight); 
00306 
00308 // measure frame rate and output to file every 30 frames.
00309 // #define BENCHMARK
00310 #ifdef BENCHMARK
00311         const float alpha = .1f;
00312         static double avgtimeDiff = 60;
00313         static int count = 0;
00314         double curtimeDiff = m_currentTime.Millisecs() - m_lastValidTime.Millisecs();
00315         avgtimeDiff = curtimeDiff * alpha + avgtimeDiff * (1-alpha);
00316         if (count++ % 30 == 0) {
00317                 FILE *fid = fopen("benchmark.txt", "a");
00318                 fprintf(fid, "%.2f\n", 1000.0/avgtimeDiff);
00319                 fclose(fid);
00320         }
00321 #endif
00322 
00323 
00324         m_lastValidTime = m_currentTime;
00325 
00326         return NOERROR;
00327 }

Here is the call graph for this function:

HRESULT Transform IMediaSample *  pIn,
IMediaSample *  pOut
 

Definition at line 188 of file MPFaceDetectorFilter.cpp.

References Copy(), and m_currentTime.

00189 {
00190         // Copy the properties across
00191         HRESULT hr = Copy(pIn, pOut);
00192         if (FAILED(hr)) {
00193                 return hr;
00194         }
00195         
00196         CRefTime temp;
00197         pIn->GetTime((REFERENCE_TIME *) &m_currentTime, (REFERENCE_TIME *)&temp);
00198         
00199         return Transform(pOut);
00200         
00201 } // Transform

Here is the call graph for this function:


Member Data Documentation

DECLARE_IUNKNOWN
 

Definition at line 12 of file MPFaceDetectorFilter.h.

CRefTime m_currentTime [private]
 

Definition at line 52 of file MPFaceDetectorFilter.h.

Referenced by Transform().

int m_effect [private]
 

Definition at line 47 of file MPFaceDetectorFilter.h.

Referenced by ReadFromStream(), and ScribbleToStream().

int m_imgHeight [private]
 

Definition at line 50 of file MPFaceDetectorFilter.h.

Referenced by Copy(), and Transform().

int m_imgWidth [private]
 

Definition at line 49 of file MPFaceDetectorFilter.h.

Referenced by Copy(), and Transform().

FilterInterface m_interface [private]
 

Definition at line 56 of file MPFaceDetectorFilter.h.

Referenced by Copy(), and Transform().

CRefTime m_lastValidTime [private]
 

Definition at line 53 of file MPFaceDetectorFilter.h.

Referenced by Transform().

const long m_lBufferRequest [private]
 

Definition at line 48 of file MPFaceDetectorFilter.h.

CCritSec m_MPFaceDetectorFilterLock [private]
 

Definition at line 46 of file MPFaceDetectorFilter.h.

CRefTime m_resetInterval [private]
 

Definition at line 54 of file MPFaceDetectorFilter.h.


The documentation for this class was generated from the following files:
Generated on Mon Nov 8 17:08:36 2004 for MPT by  doxygen 1.3.9.1