158 lines
5.2 KiB
C++
158 lines
5.2 KiB
C++
#ifndef PARKINGSPACEGUIDEPRESENTER_H
|
|
#define PARKINGSPACEGUIDEPRESENTER_H
|
|
|
|
#include <array>
|
|
#include <atomic>
|
|
#include <condition_variable>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include <QImage>
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
#include "ConfigManager.h"
|
|
#include "IMvsDevice.h"
|
|
#include "ILedDisplayDevice.h"
|
|
#include "IRsLidarDevice.h"
|
|
#include "IYParkingSpaceGuideStatus.h"
|
|
|
|
class DetectPresenter;
|
|
class IYUDPClient;
|
|
class ParkingStatusHttpServer;
|
|
struct ParkingGuideAlgorithmState;
|
|
|
|
struct CameraFrameInfo
|
|
{
|
|
int width = 0;
|
|
int height = 0;
|
|
int pixelFormat = 0;
|
|
unsigned long long frameId = 0;
|
|
unsigned long long timestamp = 0;
|
|
};
|
|
|
|
class ParkingSpaceGuidePresenter : public QObject, public IVrConfigChangeNotify
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ParkingSpaceGuidePresenter(QObject* parent = nullptr);
|
|
~ParkingSpaceGuidePresenter() override;
|
|
|
|
int Init();
|
|
void DeinitApp();
|
|
|
|
bool StartDetection(int cameraIndex = -1);
|
|
bool TriggerDetection(int cameraIndex = -1);
|
|
int StopDetection();
|
|
bool IsDetectionRunning() const;
|
|
int LoadAndDetect(const QString& fileName);
|
|
int SaveDetectionDataToFile(const std::string& filePath);
|
|
int GetDetectionDataCacheSize() const;
|
|
|
|
void SetDefaultCameraIndex(int cameraIndex);
|
|
int GetDetectIndex() const;
|
|
QString GetAlgoVersion() const;
|
|
ConfigManager* GetConfigManager();
|
|
std::vector<std::pair<std::string, void*>> GetCameraList() const;
|
|
|
|
template<typename StatusCallbackType>
|
|
void SetStatusCallback(StatusCallbackType* statusCallback)
|
|
{
|
|
m_statusCallback = static_cast<void*>(statusCallback);
|
|
}
|
|
|
|
void OnConfigChanged(const ConfigResult& configResult) override;
|
|
|
|
private:
|
|
struct OwnedCloudFrame
|
|
{
|
|
std::vector<SVzNLPointXYZI> points;
|
|
RsCloudData cloud;
|
|
RsFrameInfo info;
|
|
};
|
|
|
|
IYParkingSpaceGuideStatus* StatusCallback() const;
|
|
|
|
int InitConfig();
|
|
int InitMvsCamera(const MvsCameraConfig& config);
|
|
int InitRsLidar(const RsLidarConfig& config);
|
|
int InitLedDisplay(const LedDisplayConfig& config);
|
|
int InitUdpBroadcast(const UdpBroadcastConfig& config);
|
|
int InitHttpServer(const HttpServerConfig& config);
|
|
void CloseUdpBroadcast();
|
|
void CloseHttpServer();
|
|
void CloseDevices();
|
|
void EnrichDetectionResult(DetectionResult& result) const;
|
|
void UpdateCurrentStatus(const DetectionResult& result);
|
|
std::string CurrentStatusJson() const;
|
|
bool BroadcastDetectionResult(const DetectionResult& result);
|
|
void NotifyStatus(const std::string& message);
|
|
void NotifyWorkStatus(WorkStatus status);
|
|
void NotifyCameraStatus(bool connected);
|
|
void NotifyLidarStatus(bool connected);
|
|
void NotifyLedStatus(bool connected);
|
|
LedDisplayResult ConvertLedResult(const DetectionResult& result) const;
|
|
std::shared_ptr<OwnedCloudFrame> AcquireCloudFrameBuffer();
|
|
static bool CopyCloudFrame(const RsCloudData& cloud,
|
|
const RsFrameInfo& info,
|
|
OwnedCloudFrame& destination);
|
|
bool ProcessAirplanePresence(const RsCloudData& cloud);
|
|
bool DetectOnce(const RsCloudData& cloud, ParkingGuideAlgorithmState& algorithmState);
|
|
void PublishDetectionResult(DetectionResult& result);
|
|
void PublishErrorResult(int errorCode, const QString& message);
|
|
bool CaptureModelRecognitionImage(QImage& image, QString& errorMessage);
|
|
void DetectionLoop();
|
|
|
|
bool CacheMvsFrame(const MvsImageData& image, QImage& frame);
|
|
|
|
private:
|
|
ConfigManager* m_configManager = nullptr;
|
|
DetectPresenter* m_detectPresenter = nullptr;
|
|
IMvsDevice* m_mvsDevice = nullptr;
|
|
IRsLidarDevice* m_lidarDevice = nullptr;
|
|
ILedDisplayDevice* m_ledDisplay = nullptr;
|
|
IYUDPClient* m_udpClient = nullptr;
|
|
ParkingStatusHttpServer* m_httpServer = nullptr;
|
|
UdpBroadcastConfig m_udpBroadcastConfig;
|
|
void* m_statusCallback = nullptr;
|
|
|
|
mutable std::mutex m_dataMutex;
|
|
mutable std::mutex m_udpMutex;
|
|
mutable std::mutex m_statusMutex;
|
|
std::string m_currentStatusJson;
|
|
std::vector<unsigned char> m_latestFrame;
|
|
CameraFrameInfo m_latestFrameInfo;
|
|
bool m_hasFrame = false;
|
|
std::array<std::shared_ptr<OwnedCloudFrame>, 3> m_cloudFrameSlots;
|
|
std::shared_ptr<const OwnedCloudFrame> m_latestCloudFrame;
|
|
size_t m_nextCloudFrameSlot = 0;
|
|
unsigned long long m_cloudSequence = 0;
|
|
unsigned long long m_consumedCloudSequence = 0;
|
|
bool m_lidarErrorPending = false;
|
|
QString m_lidarErrorMessage;
|
|
|
|
std::vector<std::pair<std::string, void*>> m_cameraList;
|
|
int m_currentCameraIndex = 1;
|
|
int m_detectIndex = 1;
|
|
std::atomic<bool> m_initialized{false};
|
|
std::atomic<bool> m_reconfiguring{false};
|
|
|
|
std::atomic<bool> m_detectionRunning{false};
|
|
std::atomic<bool> m_stopDetectionRequested{false};
|
|
std::atomic<bool> m_trackingMode{false};
|
|
std::atomic<long long> m_lastProbeAcceptedMs{0};
|
|
std::atomic<bool> m_cloudCopyErrorReported{false};
|
|
std::mutex m_detectionThreadMutex;
|
|
std::mutex m_detectionExecutionMutex;
|
|
std::mutex m_reconfigurationMutex;
|
|
std::condition_variable m_detectionCondition;
|
|
std::thread m_detectionThread;
|
|
};
|
|
|
|
#endif // PARKINGSPACEGUIDEPRESENTER_H
|