1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include "stdafx.h"
#include <iostream>
#include "OpenNI.h"
int main( int argc, char** argv )
{
//
openni::OpenNI::initialize();
//
openni::Device devAnyDevice;
devAnyDevice.open( openni::ANY_DEVICE );
//
openni::VideoStream streamDepth;
streamDepth.create( devAnyDevice, openni::SENSOR_DEPTH );
streamDepth.start();
//
openni::VideoStream streamColor;
streamColor.create( devAnyDevice, openni::SENSOR_COLOR );
streamColor.start();
//
openni::VideoFrameRef frameDepth;
openni::VideoFrameRef frameColor;
for( int i = 0; i < 1000; ++ i )
{
//
streamDepth.readFrame( &frameDepth );
streamColor.readFrame( &frameColor );
//
const openni::DepthPixel* pDepth
= (const openni::DepthPixel*)frameDepth.getData();
const openni::RGB888Pixel* pColor
= (const openni::RGB888Pixel*)frameColor.getData();
//
int idx = frameDepth.getWidth() * ( frameDepth.getHeight() + 1 ) / 2;
std::cout << pDepth[idx] << "( "
<< (int)pColor[idx].r << ","
<< (int)pColor[idx].g << ","
<< (int)pColor[idx].b << ")"
<< std::endl;
}
//
streamDepth.destroy();
streamColor.destroy();
//
devAnyDevice.close();
//
openni::OpenNI::shutdown();
return 0;
} |
Partager