You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
// 定位结果共享(暗场相机复用明场相机的定位结果)
// 背景:bright/dark 两台相机拍同一产品,暗场图不做定位模型(Align_Outer/Align_Inner/Tag_Loc),
// 直接复用明场相机的定位结果(外/内轮廓 roi、标签 roi、bigmask、偏移映射)。
// 约定:复用方(暗场)相机名/通道名把 "dark" 替换为 "bright" 得到提供方(明场)的相机名/通道名,
// 同产品内按 (产品ID, 相机名, 通道名) 精确配对。
// 生命周期:产品送图开始时清理(防上一轮的脏数据);产品检测完成时清理(释放内存)。
*/
#ifndef AlignShare_H_
#define AlignShare_H_
#include <string>
#include <memory>
#include <mutex>
#include <map>
#include <opencv2/opencv.hpp>
#include "AI_Edge_Algin.h"
class AlignShare
{
public:
static AlignShare &GetInstance();
// 提供方(明场)定位成功:发布可复用的定位结果
void PublishSuccess(const std::string &strProduct, const std::string &strCamera, const std::string &strChannel,
const std::shared_ptr<AI_Edge_Algin::Edge_AI_Result> &pResult,
const cv::Size &imgSize);
// 提供方(明场)定位失败:发布失败标记,让等待方立即走回退逻辑,不必干等超时
void PublishFailed(const std::string &strProduct, const std::string &strCamera, const std::string &strChannel);
// 查询(不等待):返回是否已有条目;bSucc 表示条目是成功结果(true)还是失败标记(false)
bool TryGet(const std::string &strProduct, const std::string &strCamera, const std::string &strChannel,
bool &bSucc, std::shared_ptr<AI_Edge_Algin::Edge_AI_Result> &pResult, cv::Size &imgSize);
// 产品生命周期清理(送图开始 / 检测完成)
void ClearProduct(const std::string &strProduct);
private:
AlignShare() {}
struct AlignShareEntry_
{
bool bSucc = false; // 条目是否代表"定位成功"
std::shared_ptr<AI_Edge_Algin::Edge_AI_Result> pResult; // 定位结果(成功时有效)
cv::Size imgSize = cv::Size(0, 0); // 结果对应的原图尺寸
};
std::string MakeKey(const std::string &strProduct, const std::string &strCamera, const std::string &strChannel);
std::map<std::string, AlignShareEntry_> m_mapShare; // key: 产品ID|相机名|通道名
std::mutex m_mtx;
};
#endif