190 lines
4.8 KiB
C++
190 lines
4.8 KiB
C++
#pragma once
|
||
|
||
#include <QDialog>
|
||
#include <QNetworkRequest>
|
||
#include <QNetworkReply>
|
||
#include <QNetworkAccessManager>
|
||
#include <QImage>
|
||
#include <QThread>
|
||
#include <QDir>
|
||
#include <QTimer>
|
||
#include <QMutex>
|
||
#include <QDateTime>
|
||
#include <QLabel>
|
||
#include <QFileDialog>
|
||
|
||
#include <iostream>
|
||
#include "ui_SingleLensReflexCamera.h"
|
||
#include "AppSettings.h"
|
||
|
||
#include <fstream>
|
||
#include <opencv2/opencv.hpp>
|
||
|
||
// 包含Canon EDSDK头文件
|
||
#include "EDSDK.h"
|
||
#include "EDSDKTypes.h"
|
||
#include "EDSDKErrors.h"
|
||
|
||
typedef void(*func)();
|
||
|
||
class SingleLensReflexCameraOperation : public QObject
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
SingleLensReflexCameraOperation();
|
||
~SingleLensReflexCameraOperation();
|
||
|
||
QImage m_colorImage;
|
||
QImage m_depthImage;
|
||
void setCallback(void(*func)());
|
||
bool getRecordStatus() const { return m_isRecord; }
|
||
|
||
// 设置保存路径
|
||
void setSavePath(const QString& path);
|
||
|
||
// 获取当前实时取景图像
|
||
QImage getCurrentLiveViewImage();
|
||
|
||
void setCaptureInterval(int captureIntervalSeconds);
|
||
|
||
private:
|
||
cv::Mat frame;
|
||
func m_func;
|
||
bool m_isRecord;
|
||
|
||
// Canon EDSDK相关成员
|
||
EdsCameraRef m_camera;
|
||
bool m_isSDKInitialized;
|
||
bool m_isSessionOpen;
|
||
bool m_isLiveViewActive;
|
||
|
||
QTimer* m_captureTimer; // 拍照定时器
|
||
QTimer* m_liveViewTimer; // 实时取景定时器
|
||
|
||
QString m_savePath;
|
||
int m_imageCounter;
|
||
int m_captureIntervalMilliseconds;
|
||
QMutex m_mutex;
|
||
QMutex m_liveViewMutex;
|
||
|
||
QImage m_liveViewImage; // 当前实时取景图像
|
||
|
||
// EDSDK辅助函数
|
||
EdsError initializeSDK();
|
||
EdsError terminateSDK();
|
||
EdsError openCamera();
|
||
EdsError closeCamera();
|
||
EdsError takePicture();
|
||
EdsError setupSaveToHost();
|
||
|
||
// 实时取景相关函数
|
||
EdsError startLiveView();
|
||
EdsError stopLiveView();
|
||
EdsError downloadEvfImage();
|
||
|
||
// 静态回调函数
|
||
static EdsError EDSCALLBACK handleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid* context);
|
||
static EdsError EDSCALLBACK handlePropertyEvent(EdsPropertyEvent event, EdsPropertyID property, EdsUInt32 param, EdsVoid* context);
|
||
static EdsError EDSCALLBACK handleStateEvent(EdsStateEvent event, EdsUInt32 parameter, EdsVoid* context);
|
||
|
||
// 下载图像
|
||
EdsError downloadImage(EdsDirectoryItemRef directoryItem);
|
||
|
||
public slots:
|
||
void OpenSLRCamera();
|
||
void takePhoto();
|
||
void OpenAndTakePhotoSLRCamera();
|
||
void stopTakePhoto();
|
||
void OpenSLRCamera_callback();
|
||
void CloseSLRCamera();
|
||
void onCaptureTimer();
|
||
void onLiveViewTimer();
|
||
|
||
// 控制拍照
|
||
void startCapture(); // 开始定时拍照
|
||
void stopCapture(); // 停止定时拍照
|
||
void captureOnce(); // 拍一张照片
|
||
|
||
signals:
|
||
void PlotSignal();
|
||
void CamOpenedSignal();
|
||
void CamClosedSignal();
|
||
void ImageCapturedSignal(const QString& filePath);
|
||
void ErrorSignal(const QString& errorMsg);
|
||
|
||
// 实时取景信号
|
||
void LiveViewImageReady(const QImage& image);
|
||
void LiveViewStarted();
|
||
void LiveViewStopped();
|
||
|
||
void CaptureStartedSignal();
|
||
void CaptureStoppedSignal();
|
||
};
|
||
|
||
class SingleLensReflexCameraWindow : public QDialog
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
SingleLensReflexCameraWindow(QWidget* parent = nullptr);
|
||
~SingleLensReflexCameraWindow();
|
||
|
||
SingleLensReflexCameraOperation* m_SingleLensReflexCameraOperation;
|
||
void setDataFolder(QString dir);
|
||
void setCaptureInterval(int captureIntervalSeconds);
|
||
|
||
public Q_SLOTS:
|
||
void onSelectDataFolder();
|
||
|
||
void openSLRCamera();
|
||
void takePhoto();
|
||
void OpenAndTakePhotoSLRCamera();
|
||
void stopTakePhoto();
|
||
void onCamOpened();
|
||
void closeSLRCamera();
|
||
void onCamClosed();
|
||
void onImageCaptured(const QString& filePath);
|
||
void onError(const QString& errorMsg);
|
||
|
||
// 拍照控制
|
||
void onStartCapture();
|
||
void onStopCapture();
|
||
void onCaptureOnce();
|
||
|
||
void onCaptureStarted();
|
||
void onCaptureStopped();
|
||
|
||
void onStartTimedDataCollection(int lineNum);
|
||
void onStopTimedDataCollection();
|
||
|
||
signals:
|
||
void openSLRCameraSignal();
|
||
void takePhotoSignal();
|
||
void OpenAndTakePhotoSLRCameraSignal();
|
||
void stopTakePhotoSignal();
|
||
void closeSLRCameraSignal();
|
||
void PlotSLRImageSignal();
|
||
void SLRCamClosedSignal();
|
||
|
||
// 控制信号
|
||
void startCaptureSignal();
|
||
void stopCaptureSignal();
|
||
void captureOnceSignal();
|
||
|
||
// 实时取景信号
|
||
void LiveViewImageReady(const QImage& image);
|
||
void LiveViewStarted();
|
||
void LiveViewStopped();
|
||
private:
|
||
Ui::SingleLensReflexCameraClass ui;
|
||
QThread* m_SLRCameraThread;
|
||
|
||
// 用于显示实时取景的标签(如果UI中没有,可以动态创建)
|
||
QLabel* m_liveViewLabel;
|
||
|
||
QString m_btnOldText; // 存储拍照按钮的原始文本
|
||
|
||
bool m_isCapturing; // 是否正在定时拍照
|
||
};
|