要使用ISampleGrabberCB接口獲取幀數據,需要按照以下步驟操作:
ISampleGrabber* pSampleGrabber;
CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_ISampleGrabber, (void**)&pSampleGrabber);
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24; // 指定圖像格式為RGB24
pSampleGrabber->SetMediaType(&mt);
class GrabberCB : public ISampleGrabberCB
{
public:
STDMETHODIMP_(ULONG) AddRef() { return 1; }
STDMETHODIMP_(ULONG) Release() { return 2; }
STDMETHODIMP QueryInterface(REFIID riid, void** ppv) { return S_OK; }
STDMETHODIMP SampleCB(double Time, IMediaSample* pSample) { return S_OK; }
STDMETHODIMP BufferCB(double Time, BYTE* pBuffer, long BufferLen) { return S_OK; }
};
GrabberCB grabberCB;
pSampleGrabber->SetCallback(&grabberCB, 0);
pSampleGrabber->SetOneShot(FALSE); // 連續捕獲模式
pSampleGrabber->SetBufferSamples(TRUE); // 連續捕獲模式
STDMETHODIMP GrabberCB::SampleCB(double Time, IMediaSample* pSample)
{
BYTE* pBuffer;
pSample->GetPointer(&pBuffer);
long BufferLen = pSample->GetActualDataLength();
// 處理圖像數據
return S_OK;
}
pSampleGrabber->Release();
以上就是使用ISampleGrabberCB接口獲取幀數據的基本步驟,具體實現可以根據具體需求進行調整。