要使用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接口获取帧数据的基本步骤,具体实现可以根据具体需求进行调整。