This example requires Qt5 >= 5.9 setup for building.
7#include <QGuiApplication>
8#include <QQmlApplicationEngine>
13#include <cvb/ui/image_view_item.hpp>
14#include <cvb/minos/classifier.hpp>
15#include <cvb/minos/search_result.hpp>
17#include "minos_search.hpp"
18#include "minos_result_model.hpp"
20int main(
int argc,
char* argv[])
32 MinosResultModel minosResultModel(imageController);
35 MinosSearch minosSearch(device->Stream(), minosResultModel);
48 context->setContextProperty(
"minosResultModel", &minosResultModel);
50 context->setContextProperty(
"minosSearch", &minosSearch);
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
Controller object for the QML image view item.
Definition: image_view_item.hpp:254
static void Register()
Convenience method to register this type in QML.
Definition: image_view_item.hpp:92
static void Register()
Convenience method to register this type in QML.
Definition: image_view_item.hpp:670
void setWindowIcon(const QIcon &icon)
void load(const QUrl &url)
void setContextProperty(const QString &name, QObject *value)
QQmlContext * rootContext() const const
QUrl fromLocalFile(const QString &localFile)
4#include <cvb/device_factory.hpp>
5#include <cvb/async/single_stream_handler.hpp>
6#include <cvb/minos/classifier.hpp>
7#include <cvb/ui/image_view_item.hpp>
8#include <cvb/utilities/stop_watch.hpp>
10#include "minos_result_model.hpp"
13class MinosSearch final:
21 MinosSearch(
const Cvb::StreamPtr & stream, MinosResultModel& model);
40 Cvb::StreamPtr stream_;
42 MinosResultModel& model_;
Structure that represents an area of interest in the image.
Definition: area_2d.hpp:21
Handler object for a single stream.
Definition: decl_single_stream_handler.hpp:34
virtual void HandleAsyncStream(const Driver::StreamPtr &stream)
Asynchronously called for the registered stream.
Definition: detail_single_stream_handler.hpp:21
Image plane information container.
Definition: decl_image_plane.hpp:33
Minos classifier object.
Definition: classifier.hpp:248
Speed measurement object.
Definition: stop_watch.hpp:47
1#include "minos_search.hpp"
4#include <QQmlComponent>
6#include <cvb/ui/ui.hpp>
7#include <cvb/area_2d.hpp>
8#include <cvb/point_2d.hpp>
12const double FIRST_AREA_RADIUS = 8.0;
13const double LINE_RADIUS = 4;
14const double WORD_HEIGHT = 4;
15const double WORD_WIDTH = 4;
16const double LINE_STEP_RADIUS = 8;
21MinosSearch::MinosSearch(
const Cvb::StreamPtr & stream, MinosResultModel& model)
23 , SingleStreamHandler(stream)
25 , classifier_(
Cvb::InstallPath() +
Cvb::String(CVB_LIT(
"tutorial/Minos/Images/OCR/Training Set/Numbers.clf")))
27 , stopWatch_(
Cvb::StopWatchMode::MultiCPU)
31MinosSearch::~MinosSearch()
37void MinosSearch::StartGrab()
42void MinosSearch::StopGrab()
47void MinosSearch::Snap()
54 MinosResultData result;
57 result.List = Search(waitResult.Image->Plane(0));
58 model_.SetProcessingTime(stopWatch_.TimeSpan().count());
60 result.Image = waitResult.Image;
61 model_.PushData(result);
69 auto width =
static_cast<double>(plane.Parent().Width());
70 auto height =
static_cast<double>(plane.Parent().Height());
85 if (searchResult.Quality() < 0.1)
97 auto position = searchResult.Position();
105 SearchLine(plane, lineAoi, resultList);
116 if (searchResult.Quality() == 0.0)
127 auto lineStart = searchResult.Position();
133 auto readResult = classifier_.Read(plane, readAoi, OCR_AOI);
137 for (
const auto c : readResult)
139 MinosResultItem resultItem = { lineStart, stream.str() };
140 resultList.push_back(resultItem);
143 lineStart += LINE_STEP;
156 SearchLine(plane, nextLineAoi, resultList);
159void MinosSearch::HandleAsyncStream(
const Cvb::StreamPtr & stream)
167 MinosResultData result;
170 result.List = Search(waitResult.Image->Plane(0));
171 model_.SetProcessingTime(stopWatch_.TimeSpan().count());
173 result.Image = waitResult.Image;
174 model_.PushData(result);
Stream image that is returned, when the ring buffer interface is available on a device.
Definition: decl_ring_buffer_image.hpp:29
@ FindFirst
Stop after the first result has been found.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
@ Ok
Everything is fine, a new image arrived.
6#include <QAbstractListModel>
8#include <cvb/minos/search_result.hpp>
9#include <cvb/ui/image_view_item.hpp>
31 Q_PROPERTY(
double processingTime READ ProcessingTime NOTIFY NotifyProcessingTime);
32 Q_PROPERTY(
QString searchResultText READ SearchResultText NOTIFY NotifySearchResultText);
34 friend class MinosSearch;
38 LineText = Qt::UserRole,
39 StartPosition = Qt::UserRole + 1
54 QString SearchResultText()
const;
56 double ProcessingTime() const noexcept;
58 void SetProcessingTime(
double processingTime);
60 void PushData(const MinosResultData & data);
68 void SetSearchResultText(const
QString searchResultText);
72 Cvb::UI::ImageController& imageController_;
74 std::mutex resultMutex_;
75 std::deque<MinosResultData> resultQue_;
76 MinosResultData currentResult_;
80 double processingTime_ = std::numeric_limits<
double>::quiet_NaN();
84 void NotifyProcessingTime();
85 void NotifySearchResultText();
1#include "minos_result_model.hpp"
5#include <cvb/ui/ui.hpp>
9 , imageController_(imageController)
20 names[LineText] =
"lineText";
21 names[StartPosition] =
"startPosition";
26int MinosResultModel::rowCount(
const QModelIndex &)
const
28 return static_cast<int>(currentResult_.List.size());
37 const auto & result = currentResult_.List[index.row()];
52QString MinosResultModel::SearchResultText()
const
54 return searchResultText_;
57double MinosResultModel::ProcessingTime() const noexcept
59 return processingTime_;
62void MinosResultModel::SetProcessingTime(
double processingTime)
64 if (processingTime_ == processingTime)
66 processingTime_ = processingTime;
67 NotifyProcessingTime();
70void MinosResultModel::PushData(
const MinosResultData & data)
73 resultQue_.push_back(data);
76void MinosResultModel::Refresh()
80 if (!resultQue_.size())
82 currentResult_ = resultQue_.back();
87 for (
const auto & result : currentResult_.List)
88 stream << result.Text << CVB_LIT(
"\n");
90 imageController_.Refresh(currentResult_.Image);
93void MinosResultModel::SetSearchResultText(
const QString searchResultText)
95 if (searchResultText_ == searchResultText)
97 searchResultText_ = searchResultText;
98 NotifySearchResultText();
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition: ui.hpp:254
2import CvbQuick 1.0 as CvbQuick
3import QtQuick.Controls 1.2
4import QtQuick.Layouts 1.3
10 property int margin: 11
18 anchors.margins: margin
24 Layout.fillWidth: true
25 Layout.fillHeight: true
27 // Text result per line
30 model : minosResultModel
34 imageX : startPosition.x
35 imageY : startPosition.y
48 text: minosResultModel.searchResultText
50 wrapMode: TextEdit.WrapAnywhere
51 Layout.fillWidth: true
56 Layout.preferredWidth: 200
61 Layout.alignment: Qt.AlignCenter
66 onClicked: minosSearch.Snap()
67 enabled: !cbGrab.checked
77 if (checkedState === Qt.Checked)
78 return minosSearch.StartGrab()
80 return minosSearch.StopGrab()
88 text: "Processing time: " + String(minosResultModel.processingTime) + " ms"
90 Layout.alignment: Qt.AlignCenter