2026-06-08 17:36:13 +08:00

105 lines
3.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef MVSDEVICE_IMPL_H
#define MVSDEVICE_IMPL_H
#include "IMvsDevice.h"
#include <mutex>
#include <atomic>
#include <vector>
// 海康 MVS SDK 头文件Windows / Linux 同名)
#include "MvCameraControl.h"
/**
* @brief CMvsDevice
*
* IMvsDevice 实现类,对接海康 MVS C API。
*/
class CMvsDevice : public IMvsDevice
{
public:
CMvsDevice();
~CMvsDevice() override;
// SDK
int InitSDK() override;
int UninitSDK() override;
int GetSDKVersion(std::string& version) override;
// 枚举
int EnumerateDevices(std::vector<MvsDeviceInfo>& deviceList,
unsigned int tLayerType = 0) override;
// 打开/关闭
int OpenDevice(const std::string& serialNumber) override;
int OpenDeviceByIndex(unsigned int index) override;
int CloseDevice() override;
bool IsDeviceOpen() override;
int GetDeviceInfo(MvsDeviceInfo& info) override;
// 触发/采集
int SetTriggerMode(bool enable) override;
int SendSoftTrigger() override;
int StartAcquisition() override;
int StopAcquisition() override;
bool IsAcquisitioning() override;
// 取流
int CaptureImage(MvsImageData& image, unsigned int timeoutMs = 5000) override;
int RegisterImageCallback(MvsImageCallback callback) override;
int UnregisterImageCallback() override;
// 图像参数
int GetWidth(unsigned int& width) override;
int GetHeight(unsigned int& height) override;
int SetROI(const MvsROI& roi) override;
int GetROI(MvsROI& roi) override;
// 相机参数
int SetExposureTime(double exposureTime) override;
int GetExposureTime(double& exposureTime) override;
int SetGain(double gain) override;
int GetGain(double& gain) override;
int SetFrameRate(double frameRate) override;
int GetFrameRate(double& frameRate) override;
// 通用特性访问
int SetIntFeature(const std::string& featureName, int64_t value) override;
int GetIntFeature(const std::string& featureName, int64_t& value) override;
int SetFloatFeature(const std::string& featureName, double value) override;
int GetFloatFeature(const std::string& featureName, double& value) override;
int SetEnumFeature(const std::string& featureName, int64_t value) override;
int GetEnumFeature(const std::string& featureName, int64_t& value) override;
int SetBoolFeature(const std::string& featureName, bool value) override;
int GetBoolFeature(const std::string& featureName, bool& value) override;
int SetStringFeature(const std::string& featureName, const std::string& value) override;
int GetStringFeature(const std::string& featureName, std::string& value) override;
int ExecuteCommand(const std::string& featureName) override;
private:
// MVS 取流回调C 风格静态函数)
static void __stdcall OnFrameCallback(unsigned char* pData,
MV_FRAME_OUT_INFO_EX* pFrameInfo,
void* pUser);
// 内部:把枚举到的 MV_CC_DEVICE_INFO 转成统一的 MvsDeviceInfo
static void FillDeviceInfo(const MV_CC_DEVICE_INFO& src, MvsDeviceInfo& dst);
private:
void* m_handle{nullptr}; // 设备句柄 (MV_CC_CreateHandle 产生)
bool m_bSDKInitialized{false};
bool m_bDeviceOpen{false};
std::atomic<bool> m_bAcquisitioning{false};
// 设备信息缓存
std::vector<MV_CC_DEVICE_INFO> m_devInfoCache; // 枚举结果备份
MvsDeviceInfo m_currentDeviceInfo;
bool m_currentDeviceIsUsb{false};
// 回调
MvsImageCallback m_imageCallback;
std::mutex m_callbackMutex;
std::mutex m_deviceMutex;
};
#endif // MVSDEVICE_IMPL_H