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
|
#define _CRT_SECURE_NO_DEPRECATE
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <MSR_NuiApi.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <string>
#include "openNI.h"
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "cv.h"
#include "highgui.h"
#include <cv.h>
#include "highgui.h"
using namespace std;
using namespace cv;
int main()
{
openni::OpenNI::initialize();
openni::Device device;
device.open(openni::ANY_DEVICE);
device.setImageRegistrationMode(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR );
openni::VideoStream color;
if(device.getSensorInfo(openni::SENSOR_DEPTH) != NULL)
{ //if(depth.start() != openni::STATUS_OK)
openni::VideoFrameRef depthFrame, colorFrame;
//depth.readFrame(&depthFrame);
color.readFrame(&colorFrame);
if(depthFrame.isValid() && colorFrame.isValid())
{cv::Mat depth(480,640,CV_16UC1,(void*)depthFrame.getData(), 2*640);
cv::Mat depthNorm;
cv::normalize(depth, depthNorm, 0, 255, CV_MINMAX, CV_8UC1);
imshow("Depth", depthNorm);
cv::Mat bgrMat,rgbMat(480,640,CV_8UC3,(void*)colorFrame.getData(),3*640);
cv::cvtColor(rgbMat,bgrMat, CV_RGB2BGR);// opencv expects the image in BGR format
imshow("Color", bgrMat);
}}
//depth.stop();
//depth.destroy();
color.stop();
color.destroy();
device.close();
return 0;
} |
Partager