- 程序启动后自动连接左右相机、应用参数并完成一次白平衡 - 测量请求到达时若相机未初始化成功,再初始化一次 - 重试成功继续同一测量请求,失败返回 INITIALIZATION 和 robot_valid=false - 初始化期间允许一个待处理测量请求,并支持取消 - IPC 状态增加 initialization_in_progress - 手动白平衡先失效初始化缓存并同步更新就绪状态 - 将带宽设置收口到 CameraManager,更新接入文档 验证:MSVC x64编译通过;启动重试8、IPC9、白平衡6、抓取7项测试通过
84 lines
2.5 KiB
C++
84 lines
2.5 KiB
C++
//CameraManager.h
|
|
#pragma once
|
|
#include <QObject>
|
|
#include <QThread>
|
|
#include <QImage>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <atomic>
|
|
#include "GalaxyIncludes.h"
|
|
|
|
class CaptureWorker;
|
|
|
|
class CameraManager : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
enum CamIndex { LEFT = 0, RIGHT = 1 };
|
|
static const QString LEFT_SN;
|
|
static const QString RIGHT_SN;
|
|
|
|
explicit CameraManager(QObject* parent = nullptr);
|
|
~CameraManager();
|
|
|
|
static bool initSDK();
|
|
static void uninitSDK();
|
|
static QStringList enumerateDevices();
|
|
|
|
// Override the default serial numbers before connectCamera(). Keeping the
|
|
// serial numbers on the manager instance lets the SDK wrapper support a
|
|
// customer's cameras without changing the original application defaults.
|
|
void setSerialNumber(CamIndex idx, const QString& serialNumber);
|
|
QString serialNumber(CamIndex idx) const;
|
|
|
|
bool connectCamera(CamIndex idx);
|
|
void disconnectCamera(CamIndex idx);
|
|
bool isConnected(CamIndex idx) const;
|
|
|
|
bool startPreview(CamIndex idx);
|
|
void stopPreview(CamIndex idx);
|
|
bool isPreviewing(CamIndex idx) const { return m_thread[idx] != nullptr; }
|
|
QImage captureSingleFrame(CamIndex idx);
|
|
CGXDevicePointer getDevice(CamIndex idx) const { return m_device[idx]; }
|
|
|
|
bool setExposureTime(CamIndex idx, double us);
|
|
bool getExposureTime(CamIndex idx, double& us);
|
|
bool setGain(CamIndex idx, double dB);
|
|
bool setBandwidthLimit(CamIndex idx, bool enabled);
|
|
// Run the camera's one-shot automatic white-balance procedure.
|
|
// The camera performs the adjustment and returns to its normal state.
|
|
bool applyWhiteBalanceOnce(CamIndex idx);
|
|
bool whiteBalanceFinished(CamIndex idx, bool& finished);
|
|
|
|
signals:
|
|
void leftFrameReady(const QImage& img);
|
|
void rightFrameReady(const QImage& img);
|
|
void cameraConnected(CamIndex idx);
|
|
void cameraDisconnected(CamIndex idx);
|
|
void errorOccurred(int idx, const QString& msg);
|
|
|
|
private:
|
|
QString snForIndex(CamIndex idx) const;
|
|
CGXDevicePointer m_device[2];
|
|
bool m_connected[2];
|
|
QString m_serial[2];
|
|
QThread* m_thread[2];
|
|
CaptureWorker* m_worker[2];
|
|
};
|
|
|
|
class CaptureWorker : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
CaptureWorker(CGXDevicePointer dev);
|
|
public slots:
|
|
void startCapture();
|
|
void stopCapture();
|
|
signals:
|
|
void frameReady(const QImage& img);
|
|
void errorOccurred(const QString& msg);
|
|
private:
|
|
CGXDevicePointer m_device;
|
|
std::atomic_bool m_running;
|
|
};
|