在PS3eye USB摄像头上使用DirectShow SDK的黑屏

时间:2018-01-24 14:01:21

标签: camera directshow

我刚刚发现当另一个问题出现时,DirectShow无法检测到PS3eye相机的问题。 经测试,AM3和OpenCV可以使用构造函数VideoCapture cap(1)读取PS3eye相机。当我尝试使用函数QueryFrame()从相机中抓取帧并将其显示在计算机中时,它返回了一个黑屏。代码如下:

IplImage* CCameraDS::QueryFrame()
{
    HRESULT hr;
    if (!m_IsOpen)
    {
        return NULL;
    }
    long evCode;
    long size = 0;
    hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pMediaControl);
    if (SUCCEEDED(hr)) {
        hr = m_pMediaControl->Run();
        if (FAILED(hr))
            m_pMediaControl->Stop();
        m_pMediaControl->Release();
    }
    else {
        printf("Cannot preview graph.\n");
        return false;
    }

    m_pMediaEvent->WaitForCompletion(INFINITE, &evCode);
    m_pSampleGrabber->GetCurrentBuffer(&size, NULL);

    //if the buffer size changed
    if (size != m_nBufferSize)
    {
        if (m_pFrame)
            cvReleaseImage(&m_pFrame);
        m_nBufferSize = size;
        m_pFrame = cvCreateImage(cvSize(m_nWidth, m_nHeight), IPL_DEPTH_8U, 3);
    }
    if (m_pFrame->imageData == NULL)
    {
        return 0;
    }

    hr = m_pSampleGrabber->GetCurrentBuffer(&m_nBufferSize, (long*)m_pFrame->imageData);
    if (FAILED(hr))
        return NULL;
    cvFlip(m_pFrame);
    return m_pFrame;
}

有什么问题?我错过了什么吗?

0 个答案:

没有答案