#include "classification.hpp"
#include <QQmlEngine>
#include <QQmlComponent>
#include <cvb/ui/ui.hpp>
#include <cvb/area_2d.hpp>
#include <cvb/point_2d.hpp>
Classification::Classification(ResultModel& model)
: QObject()
, controller_(model)
{
connect(this, &Classification::NotifySource, this, &Classification::OnSourceChanged);
connect(this, &Classification::NotifySearchPredictor, this, &Classification::OnSearchPredictorChanged);
connect(this, &Classification::NotifyClassificationPredictor, this, &Classification::OnClassificationPredictorChnaged);
}
void Classification::Snap()
{
if (!device_)
return;
controller_.Update({});
auto waitResult = device_->Stream()->GetSnapshot();
if (waitResult.Status != Cvb::WaitStatus::Ok)
return;
image_ = waitResult.Image;
controller_.Refresh(image_);
}
void Classification::Classify()
{
if(!image_ || !search_ || !classification_)
return;
auto redImage = image_->Plane(0).Map();
const auto gridStep = 0.6;
const auto threshold = 0.0;
const auto locality = 1.0;
std::vector<PolimagoResult> results;
auto positions = search_->GridSearch(*redImage, redImage->Bounds(), gridStep, threshold, locality);
{
return position.Quality() < .3;
});
{
auto result = classification_->Classify(*image_, Cvb::Point2D<int>{static_cast<int>(pos.X()), static_cast<int>(pos.Y())});
return PolimagoResult(pos, result);
});
controller_.Update(results);
}
void Classification::OnSourceChanged()
{
image_.reset();
device_.reset();
search_.reset();
classification_.reset();
auto fileName = source_.toLocalFile();
if (fileName.endsWith(".vin"))
{
}
else if (fileName.endsWith(".bmp"))
{
controller_.Update({});
controller_.Refresh(image_);
}
}
void Classification::OnSearchPredictorChanged()
{
}
void Classification::OnClassificationPredictorChnaged()
{
}
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
static std::unique_ptr< Image > Load(const String &fileName)
static std::unique_ptr< ClassificationPredictor > Load(const String &fileName)
static std::unique_ptr< SearchPredictor > Load(const String &fileName)
Cvb::String QtToCvb(const QString text) noexcept