libvisiontransfer  8.3.0
imagetransfer_example.cpp
1 /*******************************************************************************
2  * Copyright (c) 2020 Nerian Vision GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #include <visiontransfer/deviceenumeration.h>
16 #include <visiontransfer/imagetransfer.h>
17 #include <visiontransfer/imageset.h>
18 #include <iostream>
19 #include <exception>
20 #include <stdio.h>
21 
22 #ifdef _MSC_VER
23 // Visual studio does not come with snprintf
24 #define snprintf _snprintf_s
25 #endif
26 
27 using namespace visiontransfer;
28 
29 int main() {
30  // Search for Nerian stereo devices
31  DeviceEnumeration deviceEnum;
32  DeviceEnumeration::DeviceList devices = deviceEnum.discoverDevices();
33  if(devices.size() == 0) {
34  std::cout << "No devices discovered!" << std::endl;
35  return -1;
36  }
37 
38  // Print devices
39  std::cout << "Discovered devices:" << std::endl;
40  for(unsigned int i = 0; i< devices.size(); i++) {
41  std::cout << devices[i].toString() << std::endl;
42  }
43  std::cout << std::endl;
44 
45  // Create an image transfer object that receives data from
46  // the first detected device
47  ImageTransfer imageTransfer(devices[0]);
48 
49  // Receive 100 images
50  for(int i=0; i<5; i++) {
51  std::cout << "Receiving image set " << i << std::endl;
52 
53  // Receive image
54  ImageSet imageSet;
55  while(!imageTransfer.receiveImageSet(imageSet)) {
56  // Keep on trying until reception is successful
57  }
58 
59  // Write all included images one after another
60  for(int imageNumber = 0; imageNumber < imageSet.getNumberOfImages(); imageNumber++) {
61  // Create PGM file
62  char fileName[100];
63  snprintf(fileName, sizeof(fileName), "image%03d_%d.pgm", i,
64  imageNumber);
65 
66  imageSet.writePgmFile(imageNumber, fileName);
67  }
68  }
69 
70  return 0;
71 }
DeviceList discoverDevices()
Discovers new devices and returns the list of all devices that have been found.
void writePgmFile(int imageNumber, const char *fileName) const
Writes one image of the set to a PGM or PPM file.
Definition: imageset.cpp:105
int getNumberOfImages() const
Returns the number of images in this set.
Definition: imageset.h:404
Class for synchronous transfer of image sets.
Definition: imagetransfer.h:36
A set of one to three images, but usually two (the left camera image and the disparity map)...
Definition: imageset.h:38
Allows for the discovery of devices in the network.
Nerian Vision Technologies