Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleVideoSource_Kinect2.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 <VideoSource/VideoSource_Kinect2.hh>
26 #include <Base/Image/ImageIO.hh>
27 #include <iostream>
28 
29 using namespace BIAS;
30 using namespace std;
31 
32 int main(int argc, char *argv[])
33 {
34  cout << "ExampleVideoSource_Kinect2 [<devID>] [<imgNum>]" << endl; // " [<devID2>]" << endl;
35  int devnum = argc > 1 ? atoi(argv[1]) : -1;
36  int imgnum = argc > 2 ? atoi(argv[2]) : 1;
37  //int devnum2 = argc > 3 ? atoi(argv[3]) : -1;
38  int res = 0;
39 
41  //VideoSource_Kinect2 cam2;
42 
44  Camera<float> depth, ir;
45 
47 
48  cam.InitImage(color);
49  cam.InitDepthImage(depth);
50  cam.InitIrImage(ir);
51 
52  if (devnum >= 0)
53  res = cam.OpenDevice(devnum);
54  else
55  res = cam.OpenDevice();
56  cout << "OpenDevice() -> " << res << endl;
57  if (res < 0) return -1;
58 
59  //if (devnum2 >= 0)
60  // cam2.OpenDevice(devnum2);
61  //else
62  // cam2.OpenDevice();
63 
64  res = cam.PreGrab();
65  //cam2.PreGrab();
66  cout << "PreGrab() -> " << res << endl;
67 
68  if (imgnum > 1)
69  cout << "Grabbing " << imgnum << " images..." << endl;
70  for (int i = 0; i < imgnum; i++) {
71  cam.GrabSingle(color);
72  cam.GrabSingleDepth(depth);
73  cam.GrabSingleIR(ir);
74  //cam2.GrabSingle(color);
75  //cam2.GrabSingleDepth(depth);
76  //cam2.GrabSingleIR(ir);
77  std::cout << "." << std::flush;
78  }
79 
80  ImageIO::Save("kinect2-color.mip", color);
81  ImageIO::Save("kinect2-depth.mip", depth);
82  ImageIO::Save("kinect2-ir.mip", ir);
83 
84  res = cam.PostGrab();
85  cout << "PostGrab() -> " << res << endl;
86 
87  cam.CloseDevice();
88  cout << "CloseDevice() -> " << res << endl;
89 
90  //cam2.PostGrab();
91  //cam2.CloseDevice();
92 
93  return 0;
94 }
void SetMode(Kinect2Mode mode)
virtual int PostGrab()
Stop grabbing.
virtual int GrabSingleDepth(BIAS::Camera< float > &image)
grab the depth image (slow).
Use the Kinect2 class to grab images from the Microsoft Kinect2.
virtual int InitDepthImage(BIAS::ImageBase &Image)
kinect 2 depth image will be 512x424, float in Millimeters
virtual int GrabSingleIR(BIAS::Camera< float > &image)
grab the raw ir data dump (very fast).
virtual int GrabSingle(BIAS::Camera< unsigned char > &image)
grab single color image. Note: This image has already been jpeg compressed
virtual int InitIrImage(BIAS::ImageBase &Image)
kinect 2 ir image will be 512x424, single channel unsigned char
get color, ir and depth images (default)
virtual int PreGrab()
Start grabbing.
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 CloseDevice()
Close device, if no other kinect cameras are in use, context is deleted (i.e. close usb bus connectio...
virtual int InitImage(BIAS::ImageBase &Image)
kinect 2 color image will be 1920x1080, RGB.