Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biaskinect2server.cpp
1 #include <Base/Image/ImageIO.hh>
2 #include <iostream>
3 
4 #include <VideoSource/VideoSource_Kinect2.hh>
5 #include <NetworkComm/CScommServer.hh>
6 
7 using namespace std;
8 using namespace BIAS;
9 
10 int main(int argc, char *argv[])
11 {
12  int devID = argc > 1 ? atoi(argv[1]) : 0;
13  int portID = argc > 2 ? atoi(argv[2]) : 8090;
14 
16  cam.SetMode(VideoSource_Kinect2::depthAndIr);
17  if (cam.OpenDevice(devID) < 0) {
18  std::cout << "Error: Failed to open device " << devID << "!" << std::endl;
19  return -1;
20  } else {
21  std::cout << "Opened device " << devID << std::endl;
22  }
23 
24  std::cout << "Initializing capture" << std::endl;
25  Camera<float> depth, ir;
26  cam.InitDepthImage(depth);
27  cam.InitIrImage(ir);
28  cam.PreGrab();
29 
30  std::cout << "Starting server" << std::endl;
31  CScommServer server;
32  unsigned int byteSize = depth.GetSizeByte();
33  server.RegisterMsg("img", BIAS::CS_BINARY, 2*byteSize);
34  server.RegisterMsg("stop", BIAS::CS_INT, 1);
35  server.RegisterMsg("ack", BIAS::CS_INT, 1);
36  server.SetVerbose(true);
37 
38  std::cout << "Wait for connections at port " << portID << std::endl;
39  server.WaitForConnections(portID);
40 
41  unsigned char *data = new unsigned char[byteSize*2];
42  unsigned char *datair = data + byteSize;
43 
44  bool doStop = false;
45  while (!doStop) {
46  cam.GrabSingleDepth(depth);
47  cam.GrabSingleIR(ir);
48  memcpy(data, depth.GetImageData(), byteSize);
49  memcpy(datair, ir.GetImageData(), byteSize);
50  server.SendMsg("img", (char*)data, 2*byteSize);
51  }
52 
53  std::cout << "Closing device" << std::endl;
54  cam.PostGrab();
55  cam.CloseDevice();
56 
57  return 0;
58 }
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).
unsigned int GetSizeByte() const
returns the nr.
Definition: ImageBase.hh:352
virtual int InitIrImage(BIAS::ImageBase &Image)
kinect 2 ir image will be 512x424, single channel unsigned char
int RegisterMsg(std::string msgName, EdataType dataType, int amount=1)
only registered msgs are accepted by commPartners Register a msg with this functions.
Definition: CScommBase.cpp:315
void WaitForConnections(unsigned int port=D_CS_DEFAULT_PORT)
Init function, returns instantly and enables the server to accept connections on the given port ...
void SetVerbose(bool on)
gives some information about establising conn, and disconnecting etc.
class for sending/receiving data between clients and serversOnly registered msgs will be accepted at ...
Definition: CScommServer.hh:55
virtual int PreGrab()
Start grabbing.
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...
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
int SendMsg(const std::string &msgName, std::vector< float > &floatData)
sends msg msgName to all connected commPartners.
Definition: CScommBase.cpp:358