i using following code sample found online. seems pick 1 frame subsequently never succeeds 'acquirelatestframe'. have exact same problem body reader. can see issue might causing this?
ikinectsensor* psensor; hresult hresult = s_ok; hresult = getdefaultkinectsensor(&psensor); if (failed(hresult)) { std::cerr << "error : getdefaultkinectsensor" << std::endl; return -1; } hresult = psensor->open(); if (failed(hresult)) { std::cerr << "error : ikinectsensor::open()" << std::endl; return -1; } // source icolorframesource* pcolorsource; hresult = psensor->get_colorframesource(&pcolorsource); if (failed(hresult)) { std::cerr << "error : ikinectsensor::get_colorframesource()" << std::endl; return -1; } // reader icolorframereader* pcolorreader; hresult = pcolorsource->openreader(&pcolorreader); if (failed(hresult)) { std::cerr << "error : icolorframesource::openreader()" << std::endl; return -1; } // description iframedescription* pdescription; hresult = pcolorsource->get_framedescription(&pdescription); if (failed(hresult)) { std::cerr << "error : icolorframesource::get_framedescription()" << std::endl; return -1; } int width = 0; int height = 0; pdescription->get_width(&width); // 1920 pdescription->get_height(&height); // 1080 unsigned int buffersize = width * height * 4 * sizeof(unsigned char); cv::mat buffermat(height, width, cv_8uc4); cv::mat colormat(height / 2, width / 2, cv_8uc4); cv::namedwindow("color"); while (1) { // frame icolorframe* pcolorframe = nullptr; hresult = pcolorreader->acquirelatestframe(&pcolorframe); if (succeeded(hresult)) { hresult = pcolorframe->copyconvertedframedatatoarray(buffersize, reinterpret_cast<byte*>(buffermat.data), colorimageformat::colorimageformat_bgra); if (succeeded(hresult)) { cv::resize(buffermat, colormat, cv::size(), 0.5, 0.5); } } else { cout << "can't aquire latest frame.\n"; } cv::imshow("color", colormat); if (cv::waitkey(30) == vk_escape) { break; } } if (psensor) { psensor->close(); } cv::destroyallwindows();
i wasn't releasing pcolorframe. doing solved issue.
Comments
Post a Comment