101 lines
3.3 KiB
C++
101 lines
3.3 KiB
C++
#pragma once
|
|||
|
|
|
||
|
|
#include <QObject>
|
||
|
|
#include <QImage>
|
||
|
|
#include <QVector>
|
||
|
|
#include <QRectF>
|
||
|
|
#include <QRect>
|
||
|
|
#include <memory>
|
||
|
|
#include "GrooveOccupancyDetector.h"
|
||
|
|
#include "GroovePoseDetector.h"
|
||
|
|
#include "VisionGuideMatcher.h"
|
||
|
|
|
||
|
|
namespace Ui { class MainWindowClass; }
|
||
|
|
class CameraManager;
|
||
|
|
class QTableWidget;
|
||
|
|
class QLabel;
|
||
|
|
class QPushButton;
|
||
|
|
class QWidget;
|
||
|
|
|
||
|
|
class GroovePanel : public QObject
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
GroovePanel(Ui::MainWindowClass& ui, CameraManager* cameraManager,
|
||
|
|
VisionGuideMatcher* matcher, QObject* parent = nullptr);
|
||
|
|
|
||
|
|
signals:
|
||
|
|
void logMessage(const QString& msg);
|
||
|
|
void resultImage(const QString& name, const QImage& image);
|
||
|
|
|
||
|
|
private slots:
|
||
|
|
void onLoadOccupancyModel();
|
||
|
|
void onRunOccupancy();
|
||
|
|
void onLoadPoseModel();
|
||
|
|
void onRunPoseLocalization();
|
||
|
|
|
||
|
|
private:
|
||
|
|
struct PoseSlot {
|
||
|
|
QRectF leftBox;
|
||
|
|
QRectF rightBox;
|
||
|
|
QVector<QPointF> leftPoints;
|
||
|
|
QVector<QPointF> rightPoints;
|
||
|
|
QVector<cv::Point3d> points3d;
|
||
|
|
QVector<double> rayErrorsMm;
|
||
|
|
cv::Point3d center;
|
||
|
|
cv::Point3d axis;
|
||
|
|
cv::Point3d normal;
|
||
|
|
QPointF leftAxisA;
|
||
|
|
QPointF leftAxisB;
|
||
|
|
double centerRayErrorMm = 0.0;
|
||
|
|
int validPointCount = 0;
|
||
|
|
bool positionValid = false;
|
||
|
|
bool axisObserved = false;
|
||
|
|
bool directionValid = false;
|
||
|
|
bool normalValid = false;
|
||
|
|
QString status = QStringLiteral("STEREO_UNMATCHED");
|
||
|
|
};
|
||
|
|
|
||
|
|
void buildTab();
|
||
|
|
void updateState();
|
||
|
|
void autoLoadModels();
|
||
|
|
bool loadOccupancyModel(const QString& path);
|
||
|
|
bool loadPoseModel(const QString& path);
|
||
|
|
QImage captureLeft(QString* sourceName = nullptr) const;
|
||
|
|
QImage captureRight(QString* sourceName = nullptr) const;
|
||
|
|
QVector<GrooveDetectionResult> detectOccupancy(const QImage& image) const;
|
||
|
|
bool inferFourPoints(const QImage& image, const QRectF& box,
|
||
|
|
QVector<QPointF>& points,
|
||
|
|
double* poseConfidence = nullptr,
|
||
|
|
double* poseIou = nullptr) const;
|
||
|
|
bool ensureCalibration();
|
||
|
|
QImage drawOccupancy(const QImage& image,
|
||
|
|
const QVector<GrooveDetectionResult>& detections) const;
|
||
|
|
QImage drawPose(const QImage& image,
|
||
|
|
const QVector<PoseSlot>& poseSlots) const;
|
||
|
|
void fillOccupancyTable(const QVector<GrooveDetectionResult>& detections);
|
||
|
|
void fillPoseTable(const QVector<PoseSlot>& poseSlots);
|
||
|
|
static cv::Point3d normalize(const cv::Point3d& p);
|
||
|
|
static double norm(const cv::Point3d& p);
|
||
|
|
static QString vecText(const cv::Point3d& p);
|
||
|
|
static QString defaultOccupancyModelPath();
|
||
|
|
static QString defaultPoseModelPath();
|
||
|
|
static QString defaultCalibPath(const QString& fileName);
|
||
|
|
static QRect cropRectForBox(const QRectF& box, const QSize& size);
|
||
|
|
|
||
|
|
Ui::MainWindowClass& ui;
|
||
|
|
CameraManager* m_cameraManager = nullptr;
|
||
|
|
VisionGuideMatcher* m_matcher = nullptr;
|
||
|
|
std::unique_ptr<GrooveOccupancyDetector> m_occupancy;
|
||
|
|
std::unique_ptr<GroovePoseDetector> m_pose;
|
||
|
|
QWidget* m_tab = nullptr;
|
||
|
|
QTableWidget* m_poseTable = nullptr;
|
||
|
|
QLabel* m_poseModelPath = nullptr;
|
||
|
|
QLabel* m_poseModelStatus = nullptr;
|
||
|
|
QLabel* m_poseStatus = nullptr;
|
||
|
|
QPushButton* m_runPose = nullptr;
|
||
|
|
bool m_occupancyLoaded = false;
|
||
|
|
bool m_poseLoaded = false;
|
||
|
|
QVector<GrooveDetectionResult> m_lastOccupancy;
|
||
|
|
};
|