Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Image Manager/Cvb++/CppStreamConsole

This example program is located in your CVB installation under %CVB%Tutorial/Image Manager/Cvb++/CppStreamConsole.

main.cpp:

// The CppStreamConsole example shows how to stream from a GenICam device.
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
#include <iostream>
#include <cvb/device_factory.hpp>
#include <cvb/utilities/system_info.hpp>
#include <cvb/driver/stream.hpp>
int main(int argc, char* argv[])
{
try
{
auto path = Cvb::InstallPath();
path += CVB_LIT("drivers/GenICam.vin");
// use command line argument if provided.
if (argc > 1)
{
std::string inputPath(argv[1]);
path = Cvb::String(inputPath.begin(), inputPath.end());
}
// expand environment variables in path
path = Cvb::ExpandPath(path);
// open a device
auto device = Cvb::DeviceFactory::Open(path, Cvb::AcquisitionStack::Vin);
// get the first stream of the device
// to get another stream call Stream(index)
auto stream = device->Stream();
// start the stream - start the acquisition
stream->Start();
for (int i = 0; i < 10; ++i)
{
// wait for an image with a timeout of 10 seconds
auto waitResult = stream->WaitFor(std::chrono::seconds(10));
if (waitResult.Status == Cvb::WaitStatus::Timeout)
throw std::runtime_error("acquisition timeout");
// get the timestamp of the image (usually a large integer number mapped to double - so better use fixed formatting)
std::cout << "Acquired image... " << std::fixed << waitResult.Image->RawTimestamp() << std::endl;
}
// synchronously stop the stream
stream->Stop();
}
catch (const std::exception& error)
{
std::cout << error.what() << std::endl;
}
}
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
String ExpandPath(const String &path)
std::string String
String InstallPath()