CVB++ 14.0
Cvb/QtImageDisplay

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/image.hpp>
13
14int main(int argc, char* argv[])
15{
16 try
17 {
18
19 QApplication app(argc, argv);
20
22 view.setWindowIcon(QIcon(":/qttutorial.png"));
25
26
27
28 // load the image
29 Cvb::ImagePtr image = Cvb::Image::Load(Cvb::InstallPath() + CVB_LIT("tutorial/ClaraRGB.bmp"));
30
31 // refresh the image view
32 view.Refresh(image);
33
34 view.show();
35
36 // display pixel data
37 view.RegisterEventMouseMoved([&](Cvb::Point2D<int> mousePos, const std::vector<double>& pixelVal)
38 {
39 // show mouse position and pixel data
40 Cvb::StringStream titleStream;
41 titleStream << "(X:" << mousePos.X() << ", Y:" << mousePos.Y() << ") (R:"
42 << qFloor(pixelVal[0]) << ", G:" << qFloor(pixelVal[1]) << ", B:" << qFloor(pixelVal[2]) << ")";
43 view.setWindowTitle(Cvb::UI::CvbToQt(titleStream.str()));
44
45 });
46
47 return app.exec();
48 }
49 catch (const std::exception& error)
50 {
51 std::cout << error.what() << std::endl;
52 }
53}
static std::unique_ptr< Image > Load(const String &fileName)
Loads an image with the given file name.
Definition: detail_image.hpp:32
T X() const noexcept
Gets the x-component of the point.
Definition: point_2d.hpp:86
T Y() const noexcept
Gets the y-component of the point.
Definition: point_2d.hpp:106
View to display an image.
Definition: decl_image_view.hpp:75
Cvb::EventCookie RegisterEventMouseMoved(std::function< void(Cvb::Point2D< int >, const std::vector< double > &)> handler)
Register a callback to get pixel values under the moving mouse.
Definition: detail_image_view.hpp:243
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
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition: ui.hpp:254
void show()
void setWindowIcon(const QIcon &icon)
void setWindowTitle(const QString &)