143 lines
3.5 KiB
C
Raw Normal View History

2026-06-26 17:55:15 +08:00
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <memory>
/**
* @brief 检测目标矩形框(图像像素坐标)
*/
struct DroneScrewBox
{
int classId{0};
float score{0.0f};
int x{0};
int y{0};
int width{0};
int height{0};
2026-07-02 10:57:32 +08:00
bool hasPhysicalHeight{false};
float physicalHeightMm{0.0f};
2026-07-03 14:19:06 +08:00
bool hasStereoMatch{false};
bool trusted{false};
int matchConfidence{1};
std::string matchStatus;
int pairId{-1};
int leftIndex{-1};
int rightIndex{-1};
2026-06-26 17:55:15 +08:00
};
/**
* @brief 单帧检测结果
*/
// Stereo distance result in millimeters.
struct DroneScrewDistance
{
int fromId{0};
int toId{0};
float distanceMm{0.0f};
};
struct DroneScrewResult
{
uint64_t frameId{0};
int64_t timestampUs{0};
int imageWidth{0};
int imageHeight{0};
std::vector<DroneScrewBox> boxes;
std::vector<DroneScrewDistance> distances;
bool success{true};
int errorCode{0};
std::string message;
2026-07-03 14:19:06 +08:00
bool isFinalResult{false};
double rankScore{0.0};
int rankSampleCount{0};
uint64_t saveIndex{0};
2026-06-26 17:55:15 +08:00
};
/**
* @brief 算法参数(页面可配置项,预留字段)
*/
struct DroneScrewAlgoParams
{
float scoreThreshold{0.5f};
float nmsThreshold{0.45f};
int inputWidth{4096};
int inputHeight{3000};
std::string modelPath; // stereo_bolt config yaml path
int modelType{1}; // 1=stereo_bolt_delivery
int expectedBoltCount{8};
// 预留位置:客户实际算法接入后可扩展
};
/**
* @brief 输入图像描述
*/
struct DroneScrewInputImage
{
const unsigned char* data{nullptr};
int width{0};
int height{0};
int stride{0};
int pixelFormat{0}; // 0=Mono8, 1=BGR8, 2=RGB8, 3=BayerRG8 ...
uint64_t frameId{0};
int64_t timestampUs{0};
};
/**
* @brief IDroneScrewAlgo
*
* 无人机螺杆/螺栓检测算法接口(预留)。
*
* 后续接入实际算法时,只需新增一个实现类替代 DroneScrewAlgoStub 即可。
*/
class IDroneScrewAlgo
{
public:
virtual ~IDroneScrewAlgo() = default;
/**
* @brief 工厂:返回当前选定实现
*/
static std::unique_ptr<IDroneScrewAlgo> CreateDefault();
/**
* @brief 初始化
*/
virtual int Init(const DroneScrewAlgoParams& params) = 0;
/**
* @brief 反初始化
*/
virtual int UnInit() = 0;
/**
* @brief 检测单帧(双目输入)
* @param leftImage 左目图像
* @param rightImage 右目图像
* @param result 检测结果
* @return 0-成功,非0-失败
*/
virtual int Detect(const DroneScrewInputImage& leftImage,
const DroneScrewInputImage& rightImage,
DroneScrewResult& result) = 0;
virtual int DetectDistance(const DroneScrewInputImage& leftImage,
const DroneScrewInputImage& rightImage,
DroneScrewResult& result) = 0;
/**
* @brief 动态更新参数
*/
virtual int UpdateParams(const DroneScrewAlgoParams& params) = 0;
/**
* @brief 算法版本字符串
*/
virtual std::string GetVersion() const = 0;
};