134 lines
4.9 KiB
C
134 lines
4.9 KiB
C
|
|
#ifndef CGALAXYDEVICE_H
|
|||
|
|
#define CGALAXYDEVICE_H
|
|||
|
|
|
|||
|
|
#include "IGalaxyDevice.h"
|
|||
|
|
#include <mutex>
|
|||
|
|
#include <string>
|
|||
|
|
#include <atomic>
|
|||
|
|
|
|||
|
|
// Galaxy SDK 头文件
|
|||
|
|
#ifdef _WIN32
|
|||
|
|
// Windows 平台使用 C++ API
|
|||
|
|
#include "GXIAPIBase.h"
|
|||
|
|
#include "IGXFactory.h"
|
|||
|
|
#include "IGXDevice.h"
|
|||
|
|
#include "IGXStream.h"
|
|||
|
|
#include "IGXFeatureControl.h"
|
|||
|
|
#include "IImageData.h"
|
|||
|
|
|
|||
|
|
using namespace GxIAPICPP;
|
|||
|
|
#else
|
|||
|
|
// Linux/ARM 平台使用 C API
|
|||
|
|
#include "GxIAPI.h"
|
|||
|
|
#include "DxImageProc.h"
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief CGalaxyDevice 实现类
|
|||
|
|
* 封装大恒Galaxy SDK,实现工业相机采集功能
|
|||
|
|
*/
|
|||
|
|
class CGalaxyDevice : public IGalaxyDevice
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
CGalaxyDevice();
|
|||
|
|
~CGalaxyDevice();
|
|||
|
|
|
|||
|
|
// SDK初始化
|
|||
|
|
int InitSDK() override;
|
|||
|
|
int UninitSDK() override;
|
|||
|
|
int GetSDKVersion(std::string& version) override;
|
|||
|
|
|
|||
|
|
// 设备枚举和连接
|
|||
|
|
int EnumerateDevices(std::vector<GalaxyDeviceInfo>& deviceList, unsigned int timeout = 1000) override;
|
|||
|
|
int OpenDevice(const std::string& serialNumber) override;
|
|||
|
|
int OpenDeviceByIndex(unsigned int index) override;
|
|||
|
|
int CloseDevice() override;
|
|||
|
|
bool IsDeviceOpen() override;
|
|||
|
|
|
|||
|
|
// 设备信息
|
|||
|
|
int GetDeviceInfo(GalaxyDeviceInfo& deviceInfo) override;
|
|||
|
|
int GetWidth(unsigned int& width) override;
|
|||
|
|
int GetHeight(unsigned int& height) override;
|
|||
|
|
|
|||
|
|
// 触发和采集控制
|
|||
|
|
int SetTriggerMode(bool enable) override;
|
|||
|
|
int SendSoftTrigger() override;
|
|||
|
|
int StartAcquisition() override;
|
|||
|
|
int StopAcquisition() override;
|
|||
|
|
bool IsAcquisitioning() override;
|
|||
|
|
|
|||
|
|
// 图像采集
|
|||
|
|
int CaptureImage(GalaxyImageData& image, unsigned int timeout = 5000) override;
|
|||
|
|
int RegisterImageCallback(GalaxyImageCallback callback) override;
|
|||
|
|
int UnregisterImageCallback() override;
|
|||
|
|
|
|||
|
|
// ROI控制
|
|||
|
|
int SetROI(const GalaxyROI& roi) override;
|
|||
|
|
int GetROI(GalaxyROI& 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 ExecuteCommand(const std::string& featureName) override;
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
#ifdef _WIN32
|
|||
|
|
// Windows 平台:采集事件处理类
|
|||
|
|
class CCaptureEventHandler : public ICaptureEventHandler
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
CCaptureEventHandler(CGalaxyDevice* pDevice) : m_pDevice(pDevice) {}
|
|||
|
|
void DoOnImageCaptured(CImageDataPointer& objImageDataPointer, void* pUserParam) override;
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
CGalaxyDevice* m_pDevice;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 处理采集到的图像
|
|||
|
|
void ProcessCapturedImage(CImageDataPointer& objImageDataPointer);
|
|||
|
|
|
|||
|
|
// 内部成员(Windows C++ API)
|
|||
|
|
CGXDevicePointer m_objDevicePtr; // 设备句柄
|
|||
|
|
CGXStreamPointer m_objStreamPtr; // 流对象
|
|||
|
|
CGXFeatureControlPointer m_objFeatureControlPtr; // 远程属性控制器
|
|||
|
|
CCaptureEventHandler* m_pCaptureEventHandler; // 采集事件处理器
|
|||
|
|
gxdeviceinfo_vector m_vectorDeviceInfo; // 设备信息缓存
|
|||
|
|
#else
|
|||
|
|
// Linux/ARM 平台:使用 C API
|
|||
|
|
GX_DEV_HANDLE m_hDevice; // 设备句柄
|
|||
|
|
void* m_pCaptureEventHandler; // 采集事件处理器(未使用)
|
|||
|
|
GX_DEVICE_BASE_INFO* m_pDeviceInfo; // 设备信息缓存
|
|||
|
|
uint32_t m_nDeviceNum; // 设备数量
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
GalaxyDeviceInfo m_deviceInfo; // 当前设备信息
|
|||
|
|
|
|||
|
|
bool m_bSDKInitialized; // SDK是否已初始化
|
|||
|
|
bool m_bDeviceOpen; // 设备是否已打开
|
|||
|
|
std::atomic<bool> m_bAcquisitioning; // 是否正在采集
|
|||
|
|
|
|||
|
|
GalaxyImageCallback m_imageCallback; // 图像回调函数
|
|||
|
|
std::mutex m_callbackMutex; // 回调互斥锁
|
|||
|
|
|
|||
|
|
// 用于CaptureImage的同步
|
|||
|
|
std::mutex m_captureMutex; // 采集互斥锁
|
|||
|
|
bool m_bNewImageReady; // 新图像是否就绪
|
|||
|
|
GalaxyImageData m_capturedImage; // 捕获的图像
|
|||
|
|
|
|||
|
|
std::mutex m_deviceMutex; // 设备操作互斥锁
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#endif // CGALAXYDEVICE_H
|