本文整理汇总了C++中IDepthFrameSource::get_FrameDescription方法的典型用法代码示例。如果您正苦于以下问题:C++ IDepthFrameSource::get_FrameDescription方法的具体用法?C++ IDepthFrameSource::get_FrameDescription怎么用?C++ IDepthFrameSource::get_FrameDescription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDepthFrameSource
的用法示例。
在下文中一共展示了IDepthFrameSource::get_FrameDescription方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initDepthFrameReader
HRESULT KinectHDFaceGrabber::initDepthFrameReader()
{
IDepthFrameSource* depthFrameSource = nullptr;
HRESULT hr = m_pKinectSensor->get_DepthFrameSource(&depthFrameSource);
IFrameDescription* frameDescription = nullptr;
if (SUCCEEDED(hr)){
hr = depthFrameSource->get_FrameDescription(&frameDescription);
}
if (SUCCEEDED(hr)){
hr = frameDescription->get_Width(&m_depthWidth);
}
if (SUCCEEDED(hr)){
hr = frameDescription->get_Height(&m_depthHeight);
}
if (SUCCEEDED(hr)){
m_depthBuffer.resize(m_depthHeight * m_depthWidth);
}
SafeRelease(frameDescription);
if (SUCCEEDED(hr)){
hr = depthFrameSource->OpenReader(&m_pDepthFrameReader);
}
SafeRelease(depthFrameSource);
return hr;
}
示例2: assert
// コンストラクタ
KinectV2::KinectV2()
{
// センサを取得する
if (sensor == NULL && GetDefaultKinectSensor(&sensor) == S_OK)
{
HRESULT hr;
// センサの使用を開始する
hr = sensor->Open();
assert(hr == S_OK);
// デプスデータの読み込み設定
IDepthFrameSource *depthSource;
hr = sensor->get_DepthFrameSource(&depthSource);
assert(hr == S_OK);
hr = depthSource->OpenReader(&depthReader);
assert(hr == S_OK);
IFrameDescription *depthDescription;
hr = depthSource->get_FrameDescription(&depthDescription);
assert(hr == S_OK);
depthSource->Release();
// デプスデータのサイズを得る
depthDescription->get_Width(&depthWidth);
depthDescription->get_Height(&depthHeight);
depthDescription->Release();
// カラーデータの読み込み設定
IColorFrameSource *colorSource;
hr = sensor->get_ColorFrameSource(&colorSource);
assert(hr == S_OK);
hr = colorSource->OpenReader(&colorReader);
assert(hr == S_OK);
IFrameDescription *colorDescription;
hr = colorSource->get_FrameDescription(&colorDescription);
assert(hr == S_OK);
colorSource->Release();
// カラーデータのサイズを得る
colorDescription->get_Width(&colorWidth);
colorDescription->get_Height(&colorHeight);
colorDescription->Release();
// 座標のマッピング
hr = sensor->get_CoordinateMapper(&coordinateMapper);
assert(hr == S_OK);
// depthCount と colorCount を計算してテクスチャとバッファオブジェクトを作成する
makeTexture();
// デプスデータからカメラ座標を求めるときに用いる一時メモリを確保する
position = new GLfloat[depthCount][3];
// カラーデータを変換する用いる一時メモリを確保する
color = new GLubyte[colorCount * 4];
}
}
示例3: getFrameInformation
void KinectDevice::getFrameInformation() {
// Get the frame information
IDepthFrameSource *depthSrc;
IColorFrameSource *colorSrc;
IInfraredFrameSource *irSrc;
ILongExposureInfraredFrameSource *hdirSrc;
IBodyIndexFrameSource *indexSrc;
IFrameDescription *depthDesc, *colorDesc, *irDesc, *hdirDesc, *indexDesc;
if (_streams & Streams::DEPTH_STREAM) {
_sensor->get_DepthFrameSource(&depthSrc);
depthSrc->get_FrameDescription(&depthDesc);
depthFrameInfo = FrameInfo(depthDesc);
// Min/max vals
depthSrc->get_DepthMinReliableDistance(&depthFrameInfo.minVal);
depthSrc->get_DepthMaxReliableDistance(&depthFrameInfo.maxVal);
// Allocate
depthData = std::shared_ptr<uint16_t>(new uint16_t[depthFrameInfo.frameSize]);
prevDepthData = std::shared_ptr<uint16_t>(new uint16_t[depthFrameInfo.frameSize]);
}
else {
depthData = nullptr;
prevDepthData = nullptr;
}
if (_streams & Streams::COLOR_STREAM) {
_sensor->get_ColorFrameSource(&colorSrc);
colorSrc->get_FrameDescription(&colorDesc);
colorFrameInfo = FrameInfo(colorDesc);
colorData = std::shared_ptr<uint16_t>(new uint16_t[colorFrameInfo.frameSize]);
}
if (_streams & Streams::IR_STREAM) {
_sensor->get_InfraredFrameSource(&irSrc);
irSrc->get_FrameDescription(&irDesc);
irFrameInfo = FrameInfo(irDesc);
irData = std::shared_ptr<uint16_t>(new uint16_t[irFrameInfo.frameSize]);
}
if (_streams & Streams::HDIR_STREAM) {
_sensor->get_LongExposureInfraredFrameSource(&hdirSrc);
hdirSrc->get_FrameDescription(&hdirDesc);
hdirFrameInfo = FrameInfo(hdirDesc);
hdirData = std::shared_ptr<uint16_t>(new uint16_t[hdirFrameInfo.frameSize]);
}
if (_streams & Streams::INDEX_STREAM) {
_sensor->get_BodyIndexFrameSource(&indexSrc);
indexSrc->get_FrameDescription(&indexDesc);
indexFrameInfo = FrameInfo(indexDesc);
indexData = std::shared_ptr<BYTE>(new BYTE[indexFrameInfo.frameSize]);
}
}
示例4: if
IFrameDescription* Kinect2StreamImpl::getFrameDescription(OniSensorType sensorType)
{
if (!m_pKinectSensor) {
return NULL;
}
IFrameDescription* frameDescription = NULL;
if (sensorType == ONI_SENSOR_COLOR) {
IColorFrameSource* frameSource = NULL;
HRESULT hr = m_pKinectSensor->get_ColorFrameSource(&frameSource);
if (SUCCEEDED(hr)) {
hr = frameSource->get_FrameDescription(&frameDescription);
if (FAILED(hr) && frameDescription) {
frameDescription->Release();
frameDescription = NULL;
}
}
if (frameSource) {
frameSource->Release();
}
}
else if (sensorType == ONI_SENSOR_DEPTH) {
IDepthFrameSource* frameSource = NULL;
HRESULT hr = m_pKinectSensor->get_DepthFrameSource(&frameSource);
if (SUCCEEDED(hr)) {
hr = frameSource->get_FrameDescription(&frameDescription);
if (FAILED(hr) && frameDescription) {
frameDescription->Release();
frameDescription = NULL;
}
}
if (frameSource) {
frameSource->Release();
}
}
else { // ONI_SENSOR_IR
IInfraredFrameSource* frameSource = NULL;
HRESULT hr = m_pKinectSensor->get_InfraredFrameSource(&frameSource);
if (SUCCEEDED(hr)) {
hr = frameSource->get_FrameDescription(&frameDescription);
if (FAILED(hr) && frameDescription) {
frameDescription->Release();
frameDescription = NULL;
}
}
if (frameSource) {
frameSource->Release();
}
}
return frameDescription;
}
示例5: main
int main(int argc, char** argv)
{
// 1a. Get default Sensor
cout << "Try to get default sensor" << endl;
IKinectSensor* pSensor = nullptr;
if (GetDefaultKinectSensor(&pSensor) != S_OK)
{
cerr << "Get Sensor failed" << endl;
}
else
{
// 1b. Open sensor
cout << "Try to open sensor" << endl;
if (pSensor->Open() != S_OK)
{
cerr << "Can't open sensor" << endl;
}
else
{
// 2a. Get frame source
cout << "Try to get source" << endl;
IDepthFrameSource* pFrameSource = nullptr;
if (pSensor->get_DepthFrameSource(&pFrameSource) != S_OK)
{
cerr << "Can't get frame source" << endl;
}
else
{
// 2b. Get frame description
int iWidth = 0;
int iHeight = 0;
IFrameDescription* pFrameDescription = nullptr;
if (pFrameSource->get_FrameDescription(&pFrameDescription) == S_OK)
{
pFrameDescription->get_Width(&iWidth);
pFrameDescription->get_Height(&iHeight);
pFrameDescription->Release();
pFrameDescription = nullptr;
}
// 2c. get some dpeth only meta
UINT16 uDepthMin = 0, uDepthMax = 0;
pFrameSource->get_DepthMinReliableDistance(&uDepthMin);
pFrameSource->get_DepthMaxReliableDistance(&uDepthMax);
cout << "Reliable Distance: " << uDepthMin << " - " << uDepthMax << endl;
// perpare OpenCV
cv::Mat mDepthImg(iHeight, iWidth, CV_16UC1);
cv::Mat mImg8bit(iHeight, iWidth, CV_8UC1);
cv::namedWindow( "Depth Map" );
// 3a. get frame reader
cout << "Try to get frame reader" << endl;
IDepthFrameReader* pFrameReader = nullptr;
if (pFrameSource->OpenReader(&pFrameReader) != S_OK)
{
cerr << "Can't get frame reader" << endl;
}
else
{
// Enter main loop
cout << "Enter main loop" << endl;
while (true)
{
// 4a. Get last frame
IDepthFrame* pFrame = nullptr;
if (pFrameReader->AcquireLatestFrame(&pFrame) == S_OK)
{
// 4c. copy the depth map to image
if (pFrame->CopyFrameDataToArray(iWidth * iHeight, reinterpret_cast<UINT16*>(mDepthImg.data)) == S_OK)
{
// 4d. convert from 16bit to 8bit
mDepthImg.convertTo(mImg8bit, CV_8U, 255.0f / uDepthMax);
cv::imshow("Depth Map", mImg8bit);
}
else
{
cerr << "Data copy error" << endl;
}
// 4e. release frame
pFrame->Release();
}
// 4f. check keyboard input
if (cv::waitKey(30) == VK_ESCAPE){
break;
}
}
// 3b. release frame reader
cout << "Release frame reader" << endl;
pFrameReader->Release();
pFrameReader = nullptr;
}
// 2d. release Frame source
cout << "Release frame source" << endl;
pFrameSource->Release();
pFrameSource = nullptr;
//.........这里部分代码省略.........
示例6: main
int main()
{
// 1. Sensor related code
cout << "Try to get default sensor" << endl;
{
if (GetDefaultKinectSensor(&pSensor) != S_OK) {
cerr << "Get Sensor failed" << endl;
return -1;
}
cout << "Try to open sensor" << endl;
if (pSensor->Open() != S_OK) {
cerr << "Can't open sensor" << endl;
return -1;
}
}
// 2. Color related code
cout << "Try to get color source" << endl;
{
// Get frame source
IColorFrameSource* pFrameSource = nullptr;
if (pSensor->get_ColorFrameSource(&pFrameSource) != S_OK) {
cerr << "Can't get color frame source" << endl;
return -1;
}
// Get frame description
cout << "get color frame description" << endl;
IFrameDescription* pFrameDescription = nullptr;
if (pFrameSource->get_FrameDescription(&pFrameDescription) == S_OK) {
pFrameDescription->get_Width(&iColorWidth);
pFrameDescription->get_Height(&iColorHeight);
uColorPointNum = iColorWidth * iColorHeight;
uColorBufferSize = uColorPointNum * 4 * sizeof(BYTE);
pCSPoints = new CameraSpacePoint[uColorPointNum];
pColorBuffer = new BYTE[4 * uColorPointNum];
}
pFrameDescription->Release();
pFrameDescription = nullptr;
// get frame reader
cout << "Try to get color frame reader" << endl;
if (pFrameSource->OpenReader(&pColorFrameReader) != S_OK) {
cerr << "Can't get color frame reader" << endl;
return -1;
}
// release Frame source
cout << "Release frame source" << endl;
pFrameSource->Release();
pFrameSource = nullptr;
}
// 3. Depth related code
cout << "Try to get depth source" << endl;
{
// Get frame source
IDepthFrameSource* pFrameSource = nullptr;
if (pSensor->get_DepthFrameSource(&pFrameSource) != S_OK) {
cerr << "Can't get depth frame source" << endl;
return -1;
}
// Get frame description
cout << "get depth frame description" << endl;
IFrameDescription* pFrameDescription = nullptr;
if (pFrameSource->get_FrameDescription(&pFrameDescription) == S_OK) {
int iDepthWidth = 0,
iDepthHeight = 0;
pFrameDescription->get_Width(&iDepthWidth);
pFrameDescription->get_Height(&iDepthHeight);
uDepthPointNum = iDepthWidth * iDepthHeight;
pDepthBuffer = new UINT16[uDepthPointNum];
}
pFrameDescription->Release();
pFrameDescription = nullptr;
// get frame reader
cout << "Try to get depth frame reader" << endl;
if (pFrameSource->OpenReader(&pDepthFrameReader) != S_OK) {
cerr << "Can't get depth frame reader" << endl;
return -1;
}
// release Frame source
cout << "Release frame source" << endl;
pFrameSource->Release();
pFrameSource = nullptr;
}
// 4. Coordinate Mapper
if (pSensor->get_CoordinateMapper(&pCoordinateMapper) != S_OK) {
cerr << "get_CoordinateMapper failed" << endl;
return -1;
}
while (1) {
//.........这里部分代码省略.........
示例7: main
int main()
{
// name and position windows
cvNamedWindow("Color Probabilistic Tracking - Samples", 1);
cvMoveWindow("Color Probabilistic Tracking - Samples", 0, 0);
cvNamedWindow("Color Probabilistic Tracking - Result", 1);
cvMoveWindow("Color Probabilistic Tracking - Result", 1000, 0);
//control mouse
setMouseCallback("Color Probabilistic Tracking - Samples", onMouse, 0);
cv::setUseOptimized(true);
// Sensor
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;
}
IDepthFrameSource* pDepthSource;
hResult = pSensor->get_DepthFrameSource(&pDepthSource);
if (FAILED(hResult)) {
std::cerr << "Error : IKinectSensor::get_DepthFrameSource()" << std::endl;
return -1;
}
/*IBodyIndexFrameSource* pBodyIndexSource;
hResult = pSensor->get_BodyIndexFrameSource(&pBodyIndexSource);*/
// Reader
IColorFrameReader* pColorReader;
hResult = pColorSource->OpenReader(&pColorReader);
if (FAILED(hResult)) {
std::cerr << "Error : IColorFrameSource::OpenReader()" << std::endl;
return -1;
}
IDepthFrameReader* pDepthReader;
hResult = pDepthSource->OpenReader(&pDepthReader);
if (FAILED(hResult)) {
std::cerr << "Error : IDepthFrameSource::OpenReader()" << std::endl;
return -1;
}
//IBodyIndexFrameReader* pBodyIndexReader;//saferealease
//hResult = pBodyIndexSource->OpenReader(&pBodyIndexReader);
// Description
IFrameDescription* pColorDescription;
hResult = pColorSource->get_FrameDescription(&pColorDescription);
if (FAILED(hResult)) {
std::cerr << "Error : IColorFrameSource::get_FrameDescription()" << std::endl;
return -1;
}
int colorWidth = 0;
int colorHeight = 0;
pColorDescription->get_Width(&colorWidth); // 1920
pColorDescription->get_Height(&colorHeight); // 1080
unsigned int colorBufferSize = colorWidth * colorHeight * 4 * sizeof(unsigned char);
cv::Mat colorBufferMat(colorHeight, colorWidth, CV_8UC4);
cv::Mat colorMat(colorHeight / 2, colorWidth / 2, CV_8UC4);
cv::namedWindow("Color");
RGBQUAD* m_pDepthRGBX;
m_pDepthRGBX = new RGBQUAD[512 * 424];// create heap storage for color pixel data in RGBX format
IFrameDescription* pDepthDescription;
hResult = pDepthSource->get_FrameDescription(&pDepthDescription);
if (FAILED(hResult)) {
std::cerr << "Error : IDepthFrameSource::get_FrameDescription()" << std::endl;
return -1;
}
int depthWidth = 0;
int depthHeight = 0;
pDepthDescription->get_Width(&depthWidth); // 512
pDepthDescription->get_Height(&depthHeight); // 424
unsigned int depthBufferSize = depthWidth * depthHeight * sizeof(unsigned short);
cv::Mat depthBufferMat(depthHeight, depthWidth, CV_16UC1);
//.........这里部分代码省略.........
示例8: _tmain
int _tmain( int argc, _TCHAR* argv[] )
{
cv::setUseOptimized( true );
// Sensor
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
IDepthFrameSource* pDepthSource;
hResult = pSensor->get_DepthFrameSource( &pDepthSource );
if( FAILED( hResult ) ){
std::cerr << "Error : IKinectSensor::get_DepthFrameSource()" << std::endl;
return -1;
}
// Reader
IDepthFrameReader* pDepthReader;
hResult = pDepthSource->OpenReader( &pDepthReader );
if( FAILED( hResult ) ){
std::cerr << "Error : IDepthFrameSource::OpenReader()" << std::endl;
return -1;
}
// Description
IFrameDescription* pDescription;
hResult = pDepthSource->get_FrameDescription( &pDescription );
if( FAILED( hResult ) ){
std::cerr << "Error : IDepthFrameSource::get_FrameDescription()" << std::endl;
return -1;
}
int width = 0;
int height = 0;
pDescription->get_Width( &width ); // 512
pDescription->get_Height( &height ); // 424
unsigned int bufferSize = width * height * sizeof( unsigned short );
cv::Mat bufferMat( height, width, CV_16UC1 );
cv::Mat depthMat( height, width, CV_8UC1 );
cv::namedWindow( "Depth" );
// Coordinate Mapper
ICoordinateMapper* pCoordinateMapper;
hResult = pSensor->get_CoordinateMapper( &pCoordinateMapper );
if( FAILED( hResult ) ){
std::cerr << "Error : IKinectSensor::get_CoordinateMapper()" << std::endl;
return -1;
}
// Create Reconstruction
NUI_FUSION_RECONSTRUCTION_PARAMETERS reconstructionParameter;
reconstructionParameter.voxelsPerMeter = 256;
reconstructionParameter.voxelCountX = 512;
reconstructionParameter.voxelCountY = 384;
reconstructionParameter.voxelCountZ = 512;
Matrix4 worldToCameraTransform;
SetIdentityMatrix( worldToCameraTransform );
INuiFusionReconstruction* pReconstruction;
hResult = NuiFusionCreateReconstruction( &reconstructionParameter, NUI_FUSION_RECONSTRUCTION_PROCESSOR_TYPE_AMP, -1, &worldToCameraTransform, &pReconstruction );
if( FAILED( hResult ) ){
std::cerr << "Error : NuiFusionCreateReconstruction()" << std::endl;
return -1;
}
// Create Image Frame
// Depth
NUI_FUSION_IMAGE_FRAME* pDepthFloatImageFrame;
hResult = NuiFusionCreateImageFrame( NUI_FUSION_IMAGE_TYPE_FLOAT, width, height, nullptr, &pDepthFloatImageFrame );
if( FAILED( hResult ) ){
std::cerr << "Error : NuiFusionCreateImageFrame( FLOAT )" << std::endl;
return -1;
}
// SmoothDepth
NUI_FUSION_IMAGE_FRAME* pSmoothDepthFloatImageFrame;
hResult = NuiFusionCreateImageFrame( NUI_FUSION_IMAGE_TYPE_FLOAT, width, height, nullptr, &pSmoothDepthFloatImageFrame );
if( FAILED( hResult ) ){
std::cerr << "Error : NuiFusionCreateImageFrame( FLOAT )" << std::endl;
return -1;
}
// Point Cloud
NUI_FUSION_IMAGE_FRAME* pPointCloudImageFrame;
hResult = NuiFusionCreateImageFrame( NUI_FUSION_IMAGE_TYPE_POINT_CLOUD, width, height, nullptr, &pPointCloudImageFrame );
if( FAILED( hResult ) ){
std::cerr << "Error : NuiFusionCreateImageFrame( POINT_CLOUD )" << std::endl;
return -1;
//.........这里部分代码省略.........
示例9: main
int main(int argc, char* argv[])
{
int similarity = 0;
string line;
ifstream myfile ("source_config.txt");
if (myfile.is_open())
{
getline (myfile,line);
hauteurCamera = stoi(line);
getline (myfile,line);
fountainXPosition = stoi(line);
getline (myfile,line);
fountainYPosition = stoi(line);
getline (myfile,line);
fountainWidth = stoi(line);
getline (myfile,line);
blasterWidth = stoi(line);
getline (myfile,line);
int numberOfBlaster = stoi(line);
for(int i = 0;i<numberOfBlaster;i++){
getline (myfile,line);
blasterXPosition.push_back(stoi(line));
getline (myfile,line);
blasterYPosition.push_back(stoi(line));
}
myfile.close();
}
else
{
cout << "Unable to open file";
exit(-1);
}
IKinectSensor* m_pKinectSensor;
IDepthFrameReader* pDepthReader;
IDepthFrameSource* pDepthFrameSource = NULL; // Depth image
IColorFrameReader* pColorReader;
IColorFrameSource* pColorFrameSource = NULL;
HRESULT hr;
hr = GetDefaultKinectSensor(&m_pKinectSensor);
if (FAILED(hr)){
cout << "ColorTrackerv2 Error : GetDefaultKinectSensor failed." << endl;
return false;
}
hr = m_pKinectSensor->Open();
if (FAILED(hr)){
cout << "ColorTrackerv2 Error : Open failed." << endl;
return false;
}
hr = m_pKinectSensor->get_DepthFrameSource( &pDepthFrameSource );
if (FAILED(hr)){
cout << "ColorTrackerv2 Error : get_DepthFrameSource failed." << endl;
return false;
}
hr = pDepthFrameSource->OpenReader( &pDepthReader );
if (FAILED(hr)){
cout << "ColorTrackerv2 Error : OpenReader failed." << endl;
return false;
}
IFrameDescription* pDepthDescription;
hr = pDepthFrameSource->get_FrameDescription( &pDepthDescription );
if( FAILED( hr ) ){
std::cerr << "Error : IDepthFrameSource::get_FrameDescription()" << std::endl;
return -1;
}
w = 0,h = 0;
pDepthDescription->get_Width( &w ); // 512
pDepthDescription->get_Height( &h ); // 424
//unsigned int irBufferSize = w * h * sizeof( unsigned short );
hr = m_pKinectSensor->get_ColorFrameSource( &pColorFrameSource );
if (FAILED(hr)){
cout << "ColorTrackerv2 Error : get_ColorFrameSource failed." << endl;
return false;
}
hr = pColorFrameSource->OpenReader( &pColorReader );
if (FAILED(hr)){
cout << "ColorTrackerv2 Error : OpenReader failed." << endl;
return false;
}
// Description
IFrameDescription* pColorDescription;
hr = pColorFrameSource->get_FrameDescription( &pColorDescription );
//.........这里部分代码省略.........
示例10: _tmain
int _tmain( int argc, _TCHAR* argv[] )
{
cv::setUseOptimized( true );
// Sensor
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
IDepthFrameSource* pDepthSource;
hResult = pSensor->get_DepthFrameSource( &pDepthSource );
if( FAILED( hResult ) ){
std::cerr << "Error : IKinectSensor::get_DepthFrameSource()" << std::endl;
return -1;
}
// Reader
IDepthFrameReader* pDepthReader;
hResult = pDepthSource->OpenReader( &pDepthReader );
if( FAILED( hResult ) ){
std::cerr << "Error : IDepthFrameSource::OpenReader()" << std::endl;
return -1;
}
// Description
IFrameDescription* pDescription;
hResult = pDepthSource->get_FrameDescription( &pDescription );
if( FAILED( hResult ) ){
std::cerr << "Error : IDepthFrameSource::get_FrameDescription()" << std::endl;
return -1;
}
int width = 0;
int height = 0;
pDescription->get_Width( &width ); // 512
pDescription->get_Height( &height ); // 424
unsigned int bufferSize = width * height * sizeof( unsigned short );
cv::Mat bufferMat( height, width, CV_16SC1 );
cv::Mat depthMat( height, width, CV_8UC1 );
cv::namedWindow( "Depth" );
while( 1 ){
// Frame
IDepthFrame* pDepthFrame = nullptr;
hResult = pDepthReader->AcquireLatestFrame( &pDepthFrame );
if( SUCCEEDED( hResult ) ){
hResult = pDepthFrame->AccessUnderlyingBuffer( &bufferSize, reinterpret_cast<UINT16**>( &bufferMat.data ) );
if( SUCCEEDED( hResult ) ){
bufferMat.convertTo( depthMat, CV_8U, -255.0f / 4500.0f, 255.0f );
}
}
SafeRelease( pDepthFrame );
cv::imshow( "Depth", depthMat );
if( cv::waitKey( 30 ) == VK_ESCAPE ){
break;
}
}
SafeRelease( pDepthSource );
SafeRelease( pDepthReader );
SafeRelease( pDescription );
if( pSensor ){
pSensor->Close();
}
SafeRelease( pSensor );
cv::destroyAllWindows();
return 0;
}
示例11: main
int main(int argc, char** argv)
{
int first_time = 0;
Size screen_size(1440, 900);//the dst image size,e.g.100x100
Scalar text_color = Scalar(0, 255, 0);
Scalar text_color2 = Scalar(0, 255, 255);
Scalar text_color3 = Scalar(0, 0, 255);
inhaler_coach coach;
coach.control = 0;
thread mThread(test_func, &coach);
// 1a. Get Kinect Sensor
cout << "Try to get default sensor" << endl;
IKinectSensor* pSensor = nullptr;
if (GetDefaultKinectSensor(&pSensor) != S_OK)
{
cerr << "Get Sensor failed" << endl;
return -1;
}
// 1b. Open sensor
cout << "Try to open sensor" << endl;
if (pSensor->Open() != S_OK)
{
cerr << "Can't open sensor" << endl;
return -1;
}
// 2. Color Related code
IColorFrameReader* pColorFrameReader = nullptr;
cv::Mat mColorImg;
UINT uBufferSize = 0;
UINT uColorPointNum = 0;
int iWidth = 0;
int iHeight = 0;
{
// 2a. Get color frame source
cout << "Try to get color source" << endl;
IColorFrameSource* pFrameSource = nullptr;
if (pSensor->get_ColorFrameSource(&pFrameSource) != S_OK)
{
cerr << "Can't get color frame source" << endl;
return -1;
}
// 2b. Get frame description
cout << "get color frame description" << endl;
IFrameDescription* pFrameDescription = nullptr;
if (pFrameSource->get_FrameDescription(&pFrameDescription) == S_OK)
{
pFrameDescription->get_Width(&iWidth);
pFrameDescription->get_Height(&iHeight);
}
pFrameDescription->Release();
pFrameDescription = nullptr;
// 2c. get frame reader
cout << "Try to get color frame reader" << endl;
if (pFrameSource->OpenReader(&pColorFrameReader) != S_OK)
{
cerr << "Can't get color frame reader" << endl;
return -1;
}
// 2d. release Frame source
cout << "Release frame source" << endl;
pFrameSource->Release();
pFrameSource = nullptr;
// Prepare OpenCV data
mColorImg = cv::Mat(iHeight, iWidth, CV_8UC4);
uBufferSize = iHeight * iWidth * 4 * sizeof(BYTE);
uColorPointNum = iHeight * iWidth;
}
// 3. Depth related code
IDepthFrameReader* pDepthFrameReader = nullptr;
UINT uDepthPointNum = 0;
int iDepthWidth = 0, iDepthHeight = 0;
cout << "Try to get depth source" << endl;
{
// Get frame source
IDepthFrameSource* pFrameSource = nullptr;
if (pSensor->get_DepthFrameSource(&pFrameSource) != S_OK)
{
cerr << "Can't get depth frame source" << endl;
return -1;
}
// Get frame description
cout << "get depth frame description" << endl;
IFrameDescription* pFrameDescription = nullptr;
if (pFrameSource->get_FrameDescription(&pFrameDescription) == S_OK)
{
pFrameDescription->get_Width(&iDepthWidth);
pFrameDescription->get_Height(&iDepthHeight);
uDepthPointNum = iDepthWidth * iDepthHeight;
}
//.........这里部分代码省略.........