130 lines
4.5 KiB
C++
130 lines
4.5 KiB
C++
#ifndef IMVSDEVICE_H
|
||
#define IMVSDEVICE_H
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
#include <functional>
|
||
|
||
// 设备传输层类型(参照 MVS CameraParams.h,统一暴露给上层)
|
||
enum class EMvsTLType
|
||
{
|
||
Unknown = 0,
|
||
GigE,
|
||
USB3,
|
||
CameraLink,
|
||
Virtual,
|
||
Other,
|
||
};
|
||
|
||
// 设备信息结构
|
||
struct MvsDeviceInfo
|
||
{
|
||
std::string serialNumber; // 序列号
|
||
std::string modelName; // 型号
|
||
std::string manufacturerName; // 厂商
|
||
std::string deviceVersion; // 设备版本
|
||
std::string userDefinedName; // 用户自定义名
|
||
std::string displayName; // 显示名(一般组合 model + sn)
|
||
std::string ipAddress; // 当前 IP(GigE)
|
||
std::string macAddress; // MAC(GigE)
|
||
EMvsTLType tlType{EMvsTLType::Unknown};
|
||
unsigned int width{0};
|
||
unsigned int height{0};
|
||
};
|
||
|
||
// 图像数据结构(同 GalaxyDevice 风格)
|
||
struct MvsImageData
|
||
{
|
||
unsigned char* pData{nullptr}; // 图像数据指针
|
||
unsigned int width{0}; // 宽
|
||
unsigned int height{0}; // 高
|
||
unsigned int dataSize{0}; // 数据大小
|
||
int pixelFormat{0}; // 像素格式(enMvGvspPixelType 透传)
|
||
unsigned long long frameID{0}; // 帧号
|
||
unsigned long long timestamp{0}; // 时间戳(设备)
|
||
};
|
||
|
||
// ROI
|
||
struct MvsROI
|
||
{
|
||
int offsetX{0};
|
||
int offsetY{0};
|
||
int width{0};
|
||
int height{0};
|
||
};
|
||
|
||
// 图像回调签名
|
||
using MvsImageCallback = std::function<void(const MvsImageData&)>;
|
||
|
||
/**
|
||
* @brief IMvsDevice 接口类
|
||
*
|
||
* 海康威视 MVS SDK 的二次封装,提供与 GalaxyDevice 一致的 C++ 接口风格。
|
||
* 同一份头文件可用于 Windows 与 Linux/ARM aarch64。
|
||
*/
|
||
class IMvsDevice
|
||
{
|
||
public:
|
||
virtual ~IMvsDevice() = default;
|
||
|
||
// 工厂
|
||
static int CreateObject(IMvsDevice** ppDevice);
|
||
|
||
// SDK 全局初始化(内部使用引用计数,可被多设备共享)
|
||
virtual int InitSDK() = 0;
|
||
virtual int UninitSDK() = 0;
|
||
virtual int GetSDKVersion(std::string& version) = 0;
|
||
|
||
// 枚举(默认枚举 GigE + USB)
|
||
virtual int EnumerateDevices(std::vector<MvsDeviceInfo>& deviceList,
|
||
unsigned int tLayerType = 0) = 0;
|
||
|
||
// 打开/关闭
|
||
virtual int OpenDevice(const std::string& serialNumber) = 0;
|
||
virtual int OpenDeviceByIndex(unsigned int index) = 0;
|
||
virtual int CloseDevice() = 0;
|
||
virtual bool IsDeviceOpen() = 0;
|
||
virtual int GetDeviceInfo(MvsDeviceInfo& info) = 0;
|
||
|
||
// 触发/采集
|
||
virtual int SetTriggerMode(bool enable) = 0;
|
||
virtual int SendSoftTrigger() = 0;
|
||
virtual int StartAcquisition() = 0;
|
||
virtual int StopAcquisition() = 0;
|
||
virtual bool IsAcquisitioning() = 0;
|
||
|
||
// 取流
|
||
virtual int CaptureImage(MvsImageData& image, unsigned int timeoutMs = 5000) = 0;
|
||
virtual int RegisterImageCallback(MvsImageCallback callback) = 0;
|
||
virtual int UnregisterImageCallback() = 0;
|
||
|
||
// 图像参数
|
||
virtual int GetWidth(unsigned int& width) = 0;
|
||
virtual int GetHeight(unsigned int& height) = 0;
|
||
virtual int SetROI(const MvsROI& roi) = 0;
|
||
virtual int GetROI(MvsROI& roi) = 0;
|
||
|
||
// 相机参数
|
||
virtual int SetExposureTime(double exposureTime) = 0;
|
||
virtual int GetExposureTime(double& exposureTime) = 0;
|
||
virtual int SetGain(double gain) = 0;
|
||
virtual int GetGain(double& gain) = 0;
|
||
virtual int SetFrameRate(double frameRate) = 0;
|
||
virtual int GetFrameRate(double& frameRate) = 0;
|
||
|
||
// 通用特性访问(基于 GenICam Node Name)
|
||
virtual int SetIntFeature(const std::string& featureName, int64_t value) = 0;
|
||
virtual int GetIntFeature(const std::string& featureName, int64_t& value) = 0;
|
||
virtual int SetFloatFeature(const std::string& featureName, double value) = 0;
|
||
virtual int GetFloatFeature(const std::string& featureName, double& value) = 0;
|
||
virtual int SetEnumFeature(const std::string& featureName, int64_t value) = 0;
|
||
virtual int GetEnumFeature(const std::string& featureName, int64_t& value) = 0;
|
||
virtual int SetBoolFeature(const std::string& featureName, bool value) = 0;
|
||
virtual int GetBoolFeature(const std::string& featureName, bool& value) = 0;
|
||
virtual int SetStringFeature(const std::string& featureName, const std::string& value) = 0;
|
||
virtual int GetStringFeature(const std::string& featureName, std::string& value) = 0;
|
||
virtual int ExecuteCommand(const std::string& featureName) = 0;
|
||
};
|
||
|
||
#endif // IMVSDEVICE_H
|