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

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

main.cpp:

// Demonstrates how image acquisition can be accomplished by using a mock GenTL Producer, so called
// CVMockTL.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <cvb/device_factory.hpp>
#include <cvb/global.hpp>
#include <cvb/driver/image_stream.hpp>
static const constexpr int DELIVERABLE_COUNT = 10; // Number of deliverables to be acquired
int main()
{
try
{
// Retrieve CVMockTL in the given system.
auto infoList = Cvb::DeviceFactory::Discover(Cvb::DiscoverFlags::IgnoreVins | // Ignores all of the CVB VINs.
Cvb::DiscoverFlags::IncludeMockTL // Include CVMockTL.
);
// Make sure if CVMockTL is on the candidate list.
Cvb::String accessToken;
for (auto n = 0; (n < infoList.size()) && accessToken.empty(); ++n)
if (infoList.at(n).AccessToken().find("MockTL") != std::string::npos)
accessToken = infoList.at(n).AccessToken();
if (accessToken.empty())
throw std::runtime_error("Could not find CVMockTL.");
// Instantiate a GenICam device from the CVMockTL.
auto device = Cvb::DeviceFactory::Open<Cvb::GenICamDevice>(accessToken, Cvb::AcquisitionStack::GenTL);
// Get the first stream of the device and start data streaming.
auto stream = device->Stream<Cvb::ImageStream>();
stream->Start();
for (auto m = 0; m < DELIVERABLE_COUNT; ++m)
{
std::cout << "Acquisition #" << m <<"\t";
// Wait for a single deliverable with a 10-second timeout value.
auto waitResult = stream->WaitFor(std::chrono::seconds(10));
if (std::get<Cvb::WaitStatus>(waitResult) == Cvb::WaitStatus::Timeout)
throw std::runtime_error("Acquisition timeout.");
// Verify the acquired deliverable contents.
auto deliverable = std::get<Cvb::MultiPartImagePtr>(waitResult);
// Retrieve the images in the deliverable.
for (auto n = 0; n < deliverable->NumParts(); ++n)
{
auto item = deliverable->GetPartAt(n);
{
auto& image = Cvb::get<Cvb::ImagePtr>(item);
std::cout << "Image property: Part index: " << n << ", Width : " << image->Width()
<< ", Height : " << image->Height()<<", ";
}
}
// Retrieve VinBuffer node map
auto& enumerator = std::get<Cvb::NodeMapEnumerator>(waitResult);
const auto names = enumerator.Names();
if (std::all_of(names.begin(), names.end(), [](const Cvb::String& name) { return name != "VinBuffer"; }))
throw std::runtime_error("The nodemap enumerator of this container does not contain a VinBuffer node map.");
auto nodeMap = enumerator.NodeMap(CVB_LIT("VinBuffer"));
// Incompleteness indicates a corrupt buffer
auto isIncompleteNode = nodeMap->TryGetNode<Cvb::BooleanNode>(CVB_LIT("IsIncomplete"));
std::cout << "IsIncomplete: " << isIncompleteNode->Value() << ", ";
// The ID of the frame that is transported in the corresponding buffer
auto frameIDNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("FrameID"));
std::cout << "FrameID: " << frameIDNode->Value() << ", ";
// The total number of bytes written into the buffer
auto sizeFilledNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("SizeFilled"));
std::cout << "SizeFilled: " << sizeFilledNode->Value() << ", ";
// The width of the frame transported in the corresponding buffer
auto widthNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("Width"));
std::cout << "Width: " << widthNode->Value() << ", ";
// The height of the frame transported in the corresponding buffer
auto heightNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("Height"));
std::cout << "Height: " << heightNode->Value() << ", ";
// Padding in x-direction
auto xPaddingNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("XPadding"));
std::cout << "XPadding: " << xPaddingNode->Value() << ", ";
// Padding in y-direction
auto yPaddingNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("YPadding"));
std::cout << "YPadding: " << yPaddingNode->Value() << ", ";
// Timestamp (UINT64) the buffer was acquired
auto timestampNode = nodeMap->TryGetNode<Cvb::IntegerNode>(CVB_LIT("Timestamp"));
std::cout << "Timestamp: " << timestampNode->Value()<<std::endl;
}
// Try aborting data streaming.
stream->TryAbort();
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
}
return 0;
}
bool Value() const
void Start() override
static std::vector< DiscoveryInformation > Discover()
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
std::int64_t Value() const
std::string String
const variant_alternative_t< I, variant< TS... > > & get(const variant< TS... > &var)
bool holds_alternative(const variant< TS... > &var) noexcept