Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Ok, I'm not getting OpenCV not throw exceptions, but OpenVR integrates nicely with OpenCV.

Take a look at the OpenVR examples HERE. The relevant one is trackedCamera_vr.

Following the sample, you get the header, if it's changed you get the buffer. However, before then you create an OpenCV mat.

    if (m_nCameraFrameBufferSize / (m_nCameraFrameHeight*m_nCameraFrameWidth) == 4)
    {
        image.create(m_nCameraFrameHeight, m_nCameraFrameWidth, CV_8UC4);
    }
    else if (m_nCameraFrameBufferSize / (m_nCameraFrameHeight*m_nCameraFrameWidth) == 3)
    {
        image.create(m_nCameraFrameHeight, m_nCameraFrameWidth, CV_8UC3);
    }

    nCameraError = m_pVRTrackedCamera->GetVideoStreamFrameBuffer(m_hTrackedCamera, vr::VRTrackedCameraFrameType_Undistorted, (uint8_t*)image.data, m_nCameraFrameBufferSize, &frameHeader, sizeof(frameHeader));

You'll notice that unlike the sample, this copies into image.data, which is your Mat. It has a reversed RGB color array, so do a cv::cvtColor(image, image, cv::COLOR_BGR2RGB); and you're good. The sample also has all the code for getting camera pose (Remember it's OpenGL, so it won't match OpenCV's rotation and translation) and camera matrix.