This example requires Qt5 >= 5.9 setup for building.
7#include <cvb/movie2/recorder.hpp>
8#include <cvb/ui/image_view.hpp>
9#include <cvb/async/single_stream_handler.hpp>
12class MainWidget :
public QWidget
17 explicit MainWidget();
18 virtual ~MainWidget() {}
21 void Load(
const QString& driver);
35 class CustomStreamHandler :
44 ~CustomStreamHandler()
50 CustomStreamHandler(
const Cvb::StreamPtr& stream, MainWidget& mainWidget)
52 , mainWidget_(mainWidget)
55 void HandleAsyncStream(
const Cvb::StreamPtr & stream)
override
62 if (mainWidget_.recorder_)
63 mainWidget_.recorder_->Write(*waitResult.Image);
66 MainWidget& mainWidget_;
Handler object for a single stream.
Definition: decl_single_stream_handler.hpp:34
Settings for initializing a direct show engine recorder.
Definition: recording_settings.hpp:94
View to display an image.
Definition: decl_image_view.hpp:75
@ Ok
Everything is fine, a new image arrived.
5#include "main_widget.hpp"
17#include <cvb/image.hpp>
18#include <cvb/device_factory.hpp>
19#include <cvb/device.hpp>
20#include <cvb/driver/driver.hpp>
21#include <cvb/driver/stream.hpp>
22#include <cvb/size_2d.hpp>
25#include <cvb/movie2/recorder.hpp>
26#include <cvb/movie2/recording_settings.hpp>
29MainWidget::MainWidget()
35 auto btnFileSelect =
new QPushButton(
"Record to...");
41 movieFile_->setText(file);
47 imageView_->resize(800, 600);
55 ,
"CVB Emulator Image Lists (*.emu);;CVB Drivers (*.vin);;Images (*.bmp *.png *.tif *.tiff *.jpg)");
63 if (state == Qt::CheckState::Checked)
66 streamHandler_->Run();
67 assert(streamHandler_->IsActive());
72 bool wait = imageView_->IsWaitForRepaintEnabled();
74 imageView_->SetWaitForRepaintEnabled(!wait);
76 streamHandler_->Finish();
78 imageView_->SetWaitForRepaintEnabled(wait);
79 assert(!streamHandler_->IsActive());
83 auto recordCheckBox =
new QCheckBox(
"Record");
101 auto codecs = settings_.AvailableCodecs();
102 for(
const auto & codec : codecs)
106 layout->addWidget(btnFileSelect, 0, 0);
107 layout->addWidget(movieFile_, 0, 1);
108 layout->addWidget(openImgBtn, 0, 2);
109 layout->addWidget(grabCheckBox_, 0, 3);
110 layout->addWidget(recordCheckBox, 1, 2, 1, 2);
111 layout->addWidget(codecComboBox, 2, 2, 1, -1);
112 layout->addWidget(imageView_, 1, 0, 3, 2);
114 Load(
Cvb::UI::CvbToQt(Cvb::InstallPath() + CVB_LIT(
"tutorial/ClassicSwitch.emu")));
120void MainWidget::Load(
const QString& driver)
126 if (fileName.
contains(
".emu", Qt::CaseInsensitive))
127 fileName = fileName.
replace(
"/",
"\\");
132 if (fileName.
contains(
".bmp", Qt::CaseInsensitive) || fileName.
contains(
".png", Qt::CaseInsensitive) || fileName.
contains(
".tif", Qt::CaseInsensitive) || fileName.
contains(
".jpg", Qt::CaseInsensitive))
135 imageView_->Refresh(image);
137 grabCheckBox_->setEnabled(
false);
145 streamHandler_ = CustomStreamHandler::Create(device->Stream(), *
this);
147 grabCheckBox_->setEnabled(
true);
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:55
static std::unique_ptr< Image > Load(const String &fileName)
Loads an image with the given file name.
Definition: detail_image.hpp:32
static std::unique_ptr< Recorder > Create(const String &path, Size2D< int > size, RecorderPixelFormat pixelFormat, const RecordingSettings &settings)
Creates a recorder object writing video streams with the given pixel format and recording engine.
Definition: recorder.hpp:96
void SetUploadMode(Cvb::UI::UploadMode uploadMode)
Set the current upload mode.
Definition: decl_image_view.hpp:357
@ Mono
Recorder writes single-plane monochrome data.
Cvb::String QtToCvb(const QString text) noexcept
Convenience converter for strings.
Definition: ui.hpp:238
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition: ui.hpp:253
void stateChanged(int state)
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QMessageBox::StandardButton critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString & replace(int position, int n, QChar after)