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

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

main.cpp:

// The QmlStreamDisplay example shows an image in a Qt display. With mouse over the pixel data are
// shown.
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
#include <iostream>
#include <QApplication>
#include <QQuickView>
#include <QQmlContext>
#include <QIcon>
#include <cvb/ui/image_view_item.hpp>
#include <cvb/device_factory.hpp>
#include <cvb/image.hpp>
#include <cvb/async/single_stream_handler.hpp>
int main(int argc, char* argv[])
{
try
{
QApplication app(argc, argv);
// register QML components for an image display
Cvb::UI::ImageViewItem::Register();
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setIcon(QIcon(":/qttutorial.png"));
auto context = view.rootContext();
// create a controller object to communicate with QML
Cvb::UI::ImageController imageController;
context->setContextProperty("mainImage", &imageController);
// load main QML file
view.setSource(QUrl::fromLocalFile("../main.qml"));
// open a device
auto device = Cvb::DeviceFactory::Open(Cvb::InstallPath() + CVB_LIT("drivers/CVMock.vin"), Cvb::AcquisitionStack::Vin);
// refresh the image display through the controller object
imageController.Refresh(device->DeviceImage(), Cvb::UI::AutoRefresh::On);
// 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())
view.resize(640, 480);
view.show();
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)
String InstallPath()