This example requires Qt5 >= 5.9 setup for building.
7#include <QGuiApplication>
8#include <QQmlApplicationEngine>
13#include <cvb/ui/image_view_item.hpp>
16#include "classification.hpp"
17#include "result_model.hpp"
19int main(
int argc,
char* argv[])
29 ResultModel resultModel(imageController);
32 Classification classification(resultModel);
45 context->setContextProperty(
"resultModel", &resultModel);
47 context->setContextProperty(
"classification", &classification);
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/polimago/search_predictor.hpp>
7#include <cvb/polimago/classification_predictor.hpp>
8#include <cvb/ui/image_view_item.hpp>
9#include <cvb/utilities/stop_watch.hpp>
11#include "result_model.hpp"
14class Classification final:
20 Q_PROPERTY(
QUrl source READ Source WRITE SetSource NOTIFY NotifySource);
21 Q_PROPERTY(
QUrl searchPredictor READ SearchPredictor WRITE SetSearchPredictor NOTIFY NotifySearchPredictor);
22 Q_PROPERTY(
QUrl classificationPredictor READ ClassificationPredictor WRITE SetClassificationPredictor NOTIFY NotifyClassificationPredictor);
27 Classification(ResultModel& model);
38 void OnSourceChanged();
39 void OnSearchPredictorChanged();
40 void OnClassificationPredictorChnaged();
49 void SetSource(
const QUrl & source)
51 if (source_ == source)
57 QUrl SearchPredictor()
const
59 return searchPredictor_;
62 void SetSearchPredictor(
const QUrl & searchPredictor)
64 if (searchPredictor_ == searchPredictor)
66 searchPredictor_ = searchPredictor;
67 NotifySearchPredictor();
70 QUrl ClassificationPredictor()
const
72 return classificationPredictor_;
75 void SetClassificationPredictor(
const QUrl & classificationPredictor)
77 if (classificationPredictor_ == classificationPredictor)
79 classificationPredictor_ = classificationPredictor;
80 NotifyClassificationPredictor();
88 QUrl searchPredictor_;
91 QUrl classificationPredictor_;
95 ResultModel& controller_;
100 void NotifySearchPredictor();
101 void NotifyClassificationPredictor();
1#include "classification.hpp"
4#include <QQmlComponent>
6#include <cvb/ui/ui.hpp>
7#include <cvb/area_2d.hpp>
8#include <cvb/point_2d.hpp>
13Classification::Classification(ResultModel& model)
17 connect(
this, &Classification::NotifySource,
this, &Classification::OnSourceChanged);
18 connect(
this, &Classification::NotifySearchPredictor,
this, &Classification::OnSearchPredictorChanged);
19 connect(
this, &Classification::NotifyClassificationPredictor,
this, &Classification::OnClassificationPredictorChnaged);
27void Classification::Snap()
32 controller_.Update({});
33 auto waitResult = device_->Stream()->GetSnapshot();
37 image_ = waitResult.Image;
38 controller_.Refresh(image_);
41void Classification::Classify()
43 if(!image_ || !search_ || !classification_)
46 auto redImage = image_->Plane(0).Map();
48 const auto gridStep = 0.6;
49 const auto threshold = 0.0;
50 const auto locality = 1.0;
55 auto positions = search_->GridSearch(*redImage, redImage->Bounds(), gridStep, threshold, locality);
58 return position.Quality() < .3;
64 auto result = classification_->Classify(*image_, Cvb::Point2D<int>{static_cast<int>(pos.X()), static_cast<int>(pos.Y())});
65 return PolimagoResult(pos, result);
69 controller_.Update(results);
72void Classification::OnSourceChanged()
78 classification_.reset();
80 auto fileName = source_.toLocalFile();
82 if (fileName.endsWith(
".vin"))
87 else if (fileName.endsWith(
".bmp"))
90 controller_.Update({});
91 controller_.Refresh(image_);
96void Classification::OnSearchPredictorChanged()
101void Classification::OnClassificationPredictorChnaged()
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
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< ClassificationPredictor > Load(const String &fileName)
Load a saved predictor from a file.
Definition: classification_predictor.hpp:129
static std::unique_ptr< SearchPredictor > Load(const String &fileName)
Load a saved predictor from a file.
Definition: search_predictor.hpp:121
Search results as provided by a Search Classifier.
Definition: search_result.hpp:21
Cvb::String QtToCvb(const QString text) noexcept
Convenience converter for strings.
Definition: ui.hpp:239
@ Ok
Everything is fine, a new image arrived.
7#include <QAbstractListModel>
10#include <cvb/point_2d.hpp>
11#include <cvb/polimago/classification_result.hpp>
12#include <cvb/polimago/search_result.hpp>
13#include <cvb/ui/ui.hpp>
14#include <cvb/ui/image_view_item.hpp>
21 : position_(
static_cast<float>(pos.
X()),
static_cast<float>(pos.
Y()))
24 , colorQuality_(result.
Quality())
28 QPointF Position()
const noexcept {
return position_; }
30 QString Name()
const noexcept {
return name_; }
32 double PosQuality()
const noexcept {
return posQuality_; }
34 double ColorQuality()
const noexcept {
return colorQuality_; }
50 friend class Classification;
54 LineText = Qt::UserRole,
55 StartPosition = Qt::UserRole + 1,
71 controller_.Refresh(image);
Polimago classification result container.
Definition: classification_result.hpp:20
String Name() const
Name of the pattern.
Definition: classification_result.hpp:36
double Quality() const noexcept
Quality / Confidence of the classification result.
Definition: classification_result.hpp:46
double Quality() const noexcept
Search result quality or confidence.
Definition: search_result.hpp:48
double Y() const noexcept
Y-position.
Definition: search_result.hpp:78
double X() const noexcept
X-position.
Definition: search_result.hpp:68
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition: ui.hpp:254
virtual QVariant data(const QModelIndex &index, int role) const const=0
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
virtual QHash< int, QByteArray > roleNames() const const
virtual int rowCount(const QModelIndex &parent) const const=0
2import CvbQuick 1.0 as CvbQuick
3import QtQuick.Controls 1.3
4import QtQuick.Layouts 1.2
5import QtQuick.Dialogs 1.2
11 property int margin: 11
19 anchors.margins: margin
25 Layout.fillWidth: true
26 Layout.fillHeight: true
28 // Text result per line
35 imageX : startPosition.x
36 imageY : startPosition.y
49 onClicked: openImageDialog.open()
54 text: "Load Search Predictor"
55 onClicked: loadSearchPredictorDialog.open()
60 text: "Load Classification Predictor"
61 onClicked: loadClassificationPredictorDialog.open()
68 onClicked: classification.Snap()
74 onClicked: classification.Classify()
85 nameFilters: [ "Image source files (*.bmp)", "Common Vision Blox driver files (*.vin)" ]
88 classification.source = openImageDialog.fileUrl;
89 var path = classification.source.toString();
90 if (path.endsWith(".bmp"))
91 btnSnap.enabled = false
93 btnSnap.enabled = true
99 id: loadSearchPredictorDialog
100 title: "Load Search Predictor"
102 nameFilters: [ "Search classifier (*.psc)" ]
103 onAccepted: classification.searchPredictor = loadSearchPredictorDialog.fileUrl;
108 id: loadClassificationPredictorDialog
109 title: "Load Classification Predictor"
111 nameFilters: [ "Classification predictor (*.pcc)" ]
112 onAccepted: classification.classificationPredictor = loadClassificationPredictorDialog.fileUrl;