MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkKinect2ControllerTest.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13#include <mitkTestingMacros.h>
15#include <mitkImage.h>
16#include <mitkIOUtil.h>
17#include <mitkPixelType.h>
18
22int mitkKinectV2ControllerTest(int /* argc */, char* /*argv*/[])
23{
24
25 MITK_TEST_BEGIN("KinectV2ControllerTest");
26 try
27 {
28 int counter = 0;
29
30
31 mitk::KinectV2Controller::Pointer kinectController = mitk::KinectV2Controller::New();
32 MITK_INFO << "connected: " << kinectController->OpenCameraConnection();
33 MITK_INFO << "CloseCameraConnection: " << kinectController->CloseCameraConnection();
34 MITK_INFO << "connected: " << kinectController->OpenCameraConnection();
35
36 for( int i = 0; i < 10; ++i)
37 {
38 //try to work with a kinect controller
39 unsigned int height = 424;
40 unsigned int width = 512;
41 float* depthArray = new float[height*width];
42 unsigned char* rgbhArray = new unsigned char[1920*1080*3];
43
44 if(!kinectController->UpdateCamera())
45 {
46 counter++;
47 continue;
48 }
49 kinectController->GetDistances(depthArray);
50 kinectController->GetRgb(rgbhArray);
51
52
53 mitk::Image::Pointer image = mitk::Image::New();
54 unsigned int dim[2];
55 dim[0] = width;
56 dim[1] = height;
57 image->Initialize(mitk::PixelType(mitk::MakeScalarPixelType<float>()), 2, dim, 1);
58 image->SetSlice(depthArray);
59
60 mitk::Image::Pointer rgbimage = mitk::Image::New();
61 unsigned int dimRGB[2];
62 dimRGB[0] = 1920;
63 dimRGB[1] = 1080;
64 rgbimage->Initialize(mitk::PixelType(mitk::MakePixelType<unsigned char, itk::RGBPixel<unsigned char>, 3>()), 2, dimRGB, 1);
65 rgbimage->SetSlice(rgbhArray);
66
67 std::stringstream ss;
68 ss << "C:/tom/test" << i << ".nrrd";
69 mitk::IOUtil::Save(image, ss.str());
70
71 std::stringstream ss2;
72 ss2 << "C:/tom/rgb" << i << ".nrrd";
73 mitk::IOUtil::Save(rgbimage, ss2.str());
74 }
75 MITK_INFO << "counter: " << counter;
76 }
77 catch(std::exception &e)
78 {
79 MITK_INFO << e.what();
80 }
81
82 MITK_TEST_END();
83
84}
int mitkKinectV2ControllerTest(int, char *[])