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

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

main.cpp:

// The QtStreamDisplay example shows a display with a stream from a GenICam device with Qt.
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
#include <iostream>
#include <QApplication>
#include <QIcon>
#include <cvb/ui/image_view.hpp>
#include <cvb/async/single_stream_handler.hpp>
#include <cvb/async/async.hpp>
#include <cvb/image.hpp>
#include <cvb/driver/stream.hpp>
#include <cvb/device_factory.hpp>
int main(int argc, char* argv[])
{
try
{
QApplication app(argc, argv);
auto path = Cvb::InstallPath();
path += CVB_LIT("drivers/CVMock.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);
// connect the device image to the UI
view.setWindowIcon(QIcon(":/qttutorial.png"));
view.SetUploadMode(Cvb::UI::UploadMode::Viewport);
view.SetRenderEngine(Cvb::UI::RenderEngine::Raster);
view.Refresh(device->DeviceImage(), Cvb::UI::AutoRefresh::On);
view.show();
// get the first stream of the device
// or use device->Stream(index) to get another stream
auto stream = device->Stream();
// create an acquisition handler for that stream and run it.
// Actually the guard starts it, and will finish it when destructed.
// There are two ways to run the acquisition:
// - Either via stream->Start() and stream->Wait() in a separate thread
// - or via SingleStreamHandler (Run() / Finish())
return app.exec();
}
catch (const std::exception& error)
{
std::cout << error.what() << std::endl;
}
}
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
static std::unique_ptr< SingleStreamHandler > Create(const Driver::StreamPtr &stream)
void SetUploadMode(Cvb::UI::UploadMode uploadMode)
void Refresh(Cvb::UI::RefreshMode refreshMode)
void SetRenderEngine(Cvb::UI::RenderEngine renderEngine)
String ExpandPath(const String &path)
std::string String
String InstallPath()