none
Getting color frame form Kinect v2 - VC++ RRS feed

  • Question

  • Hi , 

    I am trying to get color frame from kinect but it is not working... 
    It is working upto getting frame heigth. 

    #include "opencv2/imgcodecs.hpp" #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> using namespace cv; using namespace std; int main() { IColorFrameReader* m_pColorFrameReader = nullptr; RGBQUAD* m_pColorRGBX = nullptr; const int cColorWidth = 1920; const int cColorHeight = 1080; IKinectSensor * m_pKinectSensor = nullptr; HRESULT hr; hr = GetDefaultKinectSensor(&m_pKinectSensor); if (FAILED(hr)) { return hr; } if (m_pKinectSensor) { // Initialize the Kinect and get the color reader IColorFrameSource* pColorFrameSource = NULL; hr = m_pKinectSensor->Open(); if (SUCCEEDED(hr)) { hr = m_pKinectSensor->get_ColorFrameSource(&pColorFrameSource); } if (SUCCEEDED(hr)) { hr = pColorFrameSource->OpenReader(&m_pColorFrameReader); if (SUCCEEDED(hr)) { cout << "Got Color frame reader \n"; } } //SafeRelease(pColorFrameSource); } if (!m_pKinectSensor || FAILED(hr)) { cout << "Major Eror"; } Sleep(6000); /////////////////////////////// IColorFrame* pColorFrame; hr = m_pColorFrameReader->AcquireLatestFrame(&pColorFrame); if (SUCCEEDED(hr)) { cout << "Got color frame: \n"; INT64 nTime = 0; IFrameDescription* pFrameDescription = NULL; int nWidth = 0; int nHeight = 0; ColorImageFormat imageFormat = ColorImageFormat_None; UINT nBufferSize = 0; RGBQUAD *pBuffer = NULL; hr = pColorFrame->get_RelativeTime(&nTime); if (SUCCEEDED(hr)) { hr = pColorFrame->get_FrameDescription(&pFrameDescription); cout << "Frame Desc \n"; } if (SUCCEEDED(hr)) { hr = pFrameDescription->get_Width(&nWidth); cout << "Frame width \n"; } if (SUCCEEDED(hr)) { hr = pFrameDescription->get_Height(&nHeight); cout << "Frame Height \n"; } if (SUCCEEDED(hr)) { hr = pColorFrame->get_RawColorImageFormat(&imageFormat); cout << "Frame Format \n"; } if (SUCCEEDED(hr)) { if (imageFormat == ColorImageFormat_Bgra) { hr = pColorFrame->AccessRawUnderlyingBuffer(&nBufferSize, reinterpret_cast<BYTE**>(&pBuffer)); cout << "Frame color Format 1 \n"; } else if (m_pColorRGBX) { pBuffer = m_pColorRGBX; nBufferSize = cColorWidth * cColorHeight * sizeof(RGBQUAD); hr = pColorFrame->CopyConvertedFrameDataToArray(nBufferSize, reinterpret_cast<BYTE*>(pBuffer), ColorImageFormat_Bgra); cout << "Frame color Format 2 \n"; } else { hr = E_FAIL; } } if (SUCCEEDED(hr)) { cout << "Got color data from the kinect\n"; BYTE* bytepImage = reinterpret_cast<BYTE*>(pBuffer)); Mat image = Mat(1080, 1920, CV_8UC4, reinterpret_cast<void*>(bytepImage)); imshow("win",image); } //SafeRelease(pFrameDescription); } //SafeRelease(pColorFrame); //////////////////////// cout << "End of"; getchar(); return 0; }

    Please explain what I missed.. 
    Thanks in advance. 

    Wednesday, April 13, 2016 9:03 AM