Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleVideoSource_Kinect2Client.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include <Base/Debug/TimeMeasure.hh>
26 #include <VideoSource/VideoSource_Kinect2.hh>
27 #include <Base/Image/ImageIO.hh>
28 #include <NetworkComm/CScommClient.hh>
29 #include <VideoSource/VideoSource_Kinect2Net.hh>
30 #include <iostream>
31 
32 using namespace BIAS;
33 using namespace std;
34 /*
35  * int main(int argc, char *argv[]) {
36 
37  VideoSource_Kinect2 cam;
38 
39  Camera<unsigned char> color;
40  Camera<float> depth, ir;
41 
42  cam.InitImage(color);
43  cam.InitDepthImage(depth);
44  cam.InitIrImage(ir);
45 
46  CScommClient client;
47  client.SetVerbose(true);
48 
49  client.RegisterMsg("img", BIAS::CS_BINARY, 512*424*2*sizeof(float));
50 
51  client.ConnectServer("main", 8090);
52 
53  float *data = new float[512*424*2];
54  std::vector<char> binary;
55 
56  int i=0;
57  while (i<100) {
58 
59  if (client.GetData("img", binary) == 0) {
60  memcpy(data, binary.data(), 512*424*2*sizeof(float));
61  std::cout << data[100] << " " << flush;
62  }
63 
64  i++;
65 
66  }
67 
68 
69  ImageIO::Save("kinect2-color.mip", color);
70  ImageIO::Save("kinect2-depth.mip", depth);
71  ImageIO::Save("kinect2-ir.mip", ir);
72 
73  return 0;
74 }
75 */
76 int main(int argc, char *argv[]) {
77 
79 
80  Camera<float> depth, ir;
81 
82  cam.InitDepthImage(depth);
83  cam.InitIrImage(ir);
84 
85  cam.OpenDevice("main");
86  cam.PreGrab();
87 
88  TimeMeasure tm;
89  tm.Start();
90  for (int i=0;i<100;i++) {
91  cam.GrabSingleDepth(depth);
92  cam.GrabSingleIR(ir);
93  std::cout << depth.GetImageDataArray()[424/2][512/2] << " " << std::flush;
94  }
95  std::cout << std::endl;
96  tm.Stop();
97  tm.Print(std::cout);
98 
99  cam.PostGrab();
100 
101  ImageIO::Save("kinect2-depth.mip", depth);
102  ImageIO::Save("kinect2-ir.mip", ir);
103 
104  return 0;
105 }
void Print(std::ostream &os=std::cout) const
virtual int GrabSingleDepth(BIAS::Camera< float > &image)
grab the depth image (slow).
virtual int PostGrab()
Stop grabbing.
virtual int PreGrab()
Start grabbing.
virtual int InitIrImage(BIAS::ImageBase &Image)
kinect 2 ir image will be 512x424, single channel unsigned char
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
virtual int OpenDevice()
Opens first device found, OpenDevice(0)
virtual int GrabSingleIR(BIAS::Camera< float > &image)
grab the ir sum image computed from the phase images.
virtual int InitDepthImage(BIAS::ImageBase &Image)
kinect 2 depth image will be 512x424, float in Millimeters
Provides remote access to a Microsoft Kinect2 camera.
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153