CVB++ 14.1
Cvb/CppStreamConsole
1// ---------------------------------------------------------------------------
4// ---------------------------------------------------------------------------
5
6#include <iostream>
7
8#include <cvb/device_factory.hpp>
9#include <cvb/utilities/system_info.hpp>
10#include <cvb/driver/stream.hpp>
11
12int main(int argc, char* argv[])
13{
14
15
16 try
17 {
18 auto path = Cvb::InstallPath();
19 path += CVB_LIT("drivers/GenICam.vin");
20 // use command line argument if provided.
21 if (argc > 1)
22 {
23 std::string inputPath(argv[1]);
24 path = Cvb::String(inputPath.begin(), inputPath.end());
25 }
26 // expand environment variables in path
27 path = Cvb::ExpandPath(path);
28
29 // open a device
30 auto device = Cvb::DeviceFactory::Open(path, Cvb::AcquisitionStack::Vin);
31
32 // get the first stream of the device
33 // to get another stream call Stream(index)
34 auto stream = device->Stream();
35
36 // start the stream - start the acquisition
37 stream->Start();
38
39 for (int i = 0; i < 10; ++i)
40 {
41 // wait for an image with a timeout of 10 seconds
42 auto waitResult = stream->WaitFor(std::chrono::seconds(10));
43 if (waitResult.Status == Cvb::WaitStatus::Timeout)
44 throw std::runtime_error("acquisition timeout");
45
46 // get the timestamp of the image (usually a large integer number mapped to double - so better use fixed formatting)
47 std::cout << "Acquired image... " << std::fixed << waitResult.Image->RawTimestamp() << std::endl;
48 }
49
50 // synchronously stop the stream
51 stream->Stop();
52 }
53 catch (const std::exception& error)
54 {
55 std::cout << error.what() << std::endl;
56 }
57}
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
Opens a device with the given provider with its default board and port (if applicable).
Definition: decl_device_factory.hpp:55
std::string String
String for wide characters or unicode characters.
Definition: string.hpp:56
@ Timeout
A timeout occurred, no image buffer has been returned.