CVB++ 14.0
Cvb/QtStreamDisplay

This example requires Qt5 >= 5.9 setup for building.

You may build it with Ubuntu 18.04's default Qt5 after installing:

1// ---------------------------------------------------------------------------
4// ---------------------------------------------------------------------------
5
6#include <iostream>
7
8#include <QApplication>
9#include <QIcon>
10
11#include <cvb/ui/image_view.hpp>
12#include <cvb/async/single_stream_handler.hpp>
13#include <cvb/async/async.hpp>
14#include <cvb/image.hpp>
15#include <cvb/driver/stream.hpp>
16#include <cvb/device_factory.hpp>
17
18
19
20
21
22int main(int argc, char* argv[])
23{
24 try
25 {
26
27 QApplication app(argc, argv);
28
29 auto path = Cvb::InstallPath();
30 path += CVB_LIT("drivers/CVMock.vin");
31 // use command line argument if provided.
32 if (argc > 1)
33 {
34 std::string inputPath(argv[1]);
35 path = Cvb::String(inputPath.begin(), inputPath.end());
36 }
37
38 // expand environment variables in path
39 path = Cvb::ExpandPath(path);
40
41 // open a device
42 auto device = Cvb::DeviceFactory::Open(path, Cvb::AcquisitionStack::Vin);
43
44 // connect the device image to the UI
46 view.setWindowIcon(QIcon(":/qttutorial.png"));
49 view.Refresh(device->DeviceImage(), Cvb::UI::AutoRefresh::On);
50 view.show();
51
52 // get the first stream of the device
53 // or use device->Stream(index) to get another stream
54 auto stream = device->Stream();
55
56 // create an acquisition handler for that stream and run it.
57 // Actually the guard starts it, and will finish it when destructed.
58
59 // There are two ways to run the acquisition:
60 // - Either via stream->Start() and stream->Wait() in a separate thread
61 // - or via SingleStreamHandler (Run() / Finish())
62 Cvb::StreamHandlerGuard guard(Cvb::SingleStreamHandler::Create(stream), Cvb::AutoRun::Yes);
63
64
65 return app.exec();
66 }
67 catch (const std::exception& error)
68 {
69 std::cout << error.what() << std::endl;
70 }
71}
static std::unique_ptr< SingleStreamHandler > Create(const Driver::StreamPtr &stream)
Create a stream handler object.
Definition: decl_single_stream_handler.hpp:46
Handler guard object to safely run and finish a stream handler.
Definition: decl_multi_stream_handler.hpp:290
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:50
View to display an image.
Definition: decl_image_view.hpp:75
void SetUploadMode(Cvb::UI::UploadMode uploadMode)
Set the current upload mode.
Definition: decl_image_view.hpp:354
void Refresh(Cvb::UI::RefreshMode refreshMode)
Refresh the view using a specified mode.
Definition: detail_image_view.hpp:68
void SetRenderEngine(Cvb::UI::RenderEngine renderEngine)
Set the current render engine.
Definition: detail_image_view.hpp:238
std::string String
String for wide characters or unicode characters.
Definition: string.hpp:45
void show()
void setWindowIcon(const QIcon &icon)