diff --git a/HPPA/SingleLensReflexCamera.ui b/HPPA/SingleLensReflexCamera.ui
index 28093f4..1f3e692 100644
--- a/HPPA/SingleLensReflexCamera.ui
+++ b/HPPA/SingleLensReflexCamera.ui
@@ -197,11 +197,42 @@ QPushButton:pressed
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ 拍 摄
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ 停 拍
+
+
+
+
+
dataFolderLineEdit
dataFolderBtn
label
openSLRCamera_btn
+ layoutWidget
diff --git a/HPPA/SingleLensReflexCameraWindow.cpp b/HPPA/SingleLensReflexCameraWindow.cpp
index 7a8e3e9..5ab4f56 100644
--- a/HPPA/SingleLensReflexCameraWindow.cpp
+++ b/HPPA/SingleLensReflexCameraWindow.cpp
@@ -23,6 +23,11 @@ SingleLensReflexCameraWindow::SingleLensReflexCameraWindow(QWidget* parent)
connect(ui.closeSLRCamera_btn, &QPushButton::clicked, this, &SingleLensReflexCameraWindow::closeSLRCamera);
connect(this, &SingleLensReflexCameraWindow::closeSLRCameraSignal, m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::CloseSLRCamera);
+ connect(ui.takePhoto_btn, &QPushButton::clicked, this, &SingleLensReflexCameraWindow::takePhoto);
+ connect(this, &SingleLensReflexCameraWindow::takePhotoSignal, m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::takePhoto);
+ connect(ui.stopTakePhoto_btn, &QPushButton::clicked, this, &SingleLensReflexCameraWindow::stopTakePhoto);
+ connect(this, &SingleLensReflexCameraWindow::stopTakePhotoSignal, m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::stopTakePhoto);
+
connect(m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::CamOpenedSignal, this, &SingleLensReflexCameraWindow::onCamOpened);
connect(m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::CamClosedSignal, this, &SingleLensReflexCameraWindow::onCamClosed);
@@ -40,6 +45,10 @@ SingleLensReflexCameraWindow::SingleLensReflexCameraWindow(QWidget* parent)
connect(m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::LiveViewStarted, this, &SingleLensReflexCameraWindow::LiveViewStarted);
connect(m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::LiveViewStopped, this, &SingleLensReflexCameraWindow::LiveViewStopped);
+ // 拍照状态信号连接
+ connect(m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::CaptureStartedSignal, this, &SingleLensReflexCameraWindow::onCaptureStarted);
+ connect(m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::CaptureStoppedSignal, this, &SingleLensReflexCameraWindow::onCaptureStopped);
+
// 拍照控制信号连接
connect(this, &SingleLensReflexCameraWindow::startCaptureSignal, m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::startCapture);
connect(this, &SingleLensReflexCameraWindow::stopCaptureSignal, m_SingleLensReflexCameraOperation, &SingleLensReflexCameraOperation::stopCapture);
@@ -91,6 +100,22 @@ void SingleLensReflexCameraWindow::openSLRCamera()
}
}
+void SingleLensReflexCameraWindow::takePhoto()
+{
+ if (m_SingleLensReflexCameraOperation->getRecordStatus())
+ {
+ emit takePhotoSignal();
+ }
+}
+
+void SingleLensReflexCameraWindow::stopTakePhoto()
+{
+ if (m_SingleLensReflexCameraOperation->getRecordStatus())
+ {
+ emit stopTakePhotoSignal();
+ }
+}
+
void SingleLensReflexCameraWindow::onCamOpened()
{
ui.openSLRCamera_btn->setEnabled(false);
@@ -112,6 +137,22 @@ void SingleLensReflexCameraWindow::onCamClosed()
m_isCapturing = false;
}
+void SingleLensReflexCameraWindow::onCaptureStarted()
+{
+ ui.takePhoto_btn->setEnabled(false);
+ ui.stopTakePhoto_btn->setEnabled(true);
+
+ m_btnOldText = ui.takePhoto_btn->text();
+ ui.takePhoto_btn->setText(QString::fromLocal8Bit("采集中"));
+}
+
+void SingleLensReflexCameraWindow::onCaptureStopped()
+{
+ ui.takePhoto_btn->setEnabled(true);
+ ui.stopTakePhoto_btn->setEnabled(false);
+ ui.takePhoto_btn->setText(m_btnOldText);
+}
+
void SingleLensReflexCameraWindow::onImageCaptured(const QString& filePath)
{
std::cout << "Image captured: " << filePath.toStdString() << std::endl;
@@ -153,13 +194,11 @@ void SingleLensReflexCameraWindow::onCaptureOnce()
SingleLensReflexCameraOperation::SingleLensReflexCameraOperation()
{
m_func = nullptr;
- record = false;
+ m_isRecord = false;
m_camera = nullptr;
m_isSDKInitialized = false;
m_isSessionOpen = false;
m_isLiveViewActive = false;
- m_captureTimer = nullptr;
- m_liveViewTimer = nullptr;
m_imageCounter = 0;
// 设置保存路径(从 AppSettings 获取,如果为空则使用默认的 CapturedImages 目录)
@@ -172,16 +211,37 @@ SingleLensReflexCameraOperation::SingleLensReflexCameraOperation()
dir.mkpath(m_savePath);
}
+ // 创建定时器
+ m_captureTimer = new QTimer(this);
+ connect(m_captureTimer, &QTimer::timeout, this, &SingleLensReflexCameraOperation::onCaptureTimer);
+
+ m_liveViewTimer = new QTimer(this);
+ connect(m_liveViewTimer, &QTimer::timeout, this, &SingleLensReflexCameraOperation::onLiveViewTimer);
+
g_cameraOperation = this;
}
SingleLensReflexCameraOperation::~SingleLensReflexCameraOperation()
{
- if (record)
+ if (m_isRecord)
{
CloseSLRCamera();
}
g_cameraOperation = nullptr;
+
+ // 销毁定时器
+ if (m_captureTimer)
+ {
+ m_captureTimer->stop();
+ m_captureTimer->deleteLater();
+ m_captureTimer = nullptr;
+ }
+ if (m_liveViewTimer)
+ {
+ m_liveViewTimer->stop();
+ m_liveViewTimer->deleteLater();
+ m_liveViewTimer = nullptr;
+ }
}
void SingleLensReflexCameraOperation::setSavePath(const QString& path)
@@ -548,7 +608,7 @@ EdsError SingleLensReflexCameraOperation::downloadImage(EdsDirectoryItemRef dire
// 生成保存文件名(使用时间戳)
QString timestamp = QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss_zzz");
- QString fileName = m_savePath + "IMG_" + timestamp + "_" + QString::fromLocal8Bit(dirItemInfo.szFileName);
+ QString fileName = m_savePath + QDir::separator() + "IMG_" + timestamp + "_" + QString::fromLocal8Bit(dirItemInfo.szFileName);
std::cout << "Downloading image to: " << fileName.toStdString() << std::endl;
@@ -642,7 +702,7 @@ EdsError EDSCALLBACK SingleLensReflexCameraOperation::handleStateEvent(EdsStateE
{
case kEdsStateEvent_Shutdown:
std::cout << "Camera disconnected" << std::endl;
- if (pThis != nullptr && pThis->record)
+ if (pThis != nullptr && pThis->m_isRecord)
{
pThis->CloseSLRCamera();
}
@@ -703,22 +763,39 @@ void SingleLensReflexCameraOperation::OpenSLRCamera()
// 实时取景启动失败不是致命错误,继续执行
}
- record = true;
+ m_isRecord = true;
- // 创建实时取景定时器(约30fps)
- m_liveViewTimer = new QTimer(this);
- connect(m_liveViewTimer, &QTimer::timeout, this, &SingleLensReflexCameraOperation::onLiveViewTimer);
- m_liveViewTimer->start(33); // 约30fps
-
- // 创建拍照定时器(1秒拍一张),但不立即启动
- m_captureTimer = new QTimer(this);
- connect(m_captureTimer, &QTimer::timeout, this, &SingleLensReflexCameraOperation::onCaptureTimer);
- // 默认启动定时拍照
- m_captureTimer->start(3000); // 1000毫秒 = 1秒
+ // 启动实时取景定时器(约30fps)
+ if (m_liveViewTimer && !m_liveViewTimer->isActive()) {
+ m_liveViewTimer->start(33); // 约30fps
+ }
emit CamOpenedSignal();
- std::cout << "Camera opened, live view started, capture timer started (1 photo per second)" << std::endl;
+ std::cout << "Camera opened, live view started." << std::endl;
+}
+
+void SingleLensReflexCameraOperation::takePhoto()
+{
+ // 启动拍照定时器(每3秒拍一张)
+ if (m_captureTimer && !m_captureTimer->isActive())
+ {
+ m_captureTimer->start(3000);
+ std::cout << "capture timer started (1 photo 3 second)" << std::endl;
+
+ emit CaptureStartedSignal();
+ }
+}
+
+void SingleLensReflexCameraOperation::stopTakePhoto()
+{
+ if (m_captureTimer && m_captureTimer->isActive())
+ {
+ m_captureTimer->stop();
+ std::cout << "capture timer stopped" << std::endl;
+
+ emit CaptureStoppedSignal();
+ }
}
void SingleLensReflexCameraOperation::OpenSLRCamera_callback()
@@ -733,7 +810,7 @@ void SingleLensReflexCameraOperation::setCallback(void(*func)())
void SingleLensReflexCameraOperation::onLiveViewTimer()
{
- if (!record || !m_isLiveViewActive)
+ if (!m_isRecord || !m_isLiveViewActive)
{
return;
}
@@ -747,7 +824,7 @@ void SingleLensReflexCameraOperation::onLiveViewTimer()
void SingleLensReflexCameraOperation::onCaptureTimer()
{
- if (!record)
+ if (!m_isRecord)
{
return;
}
@@ -776,6 +853,7 @@ void SingleLensReflexCameraOperation::startCapture()
{
m_captureTimer->start(1000);
std::cout << "Capture timer started" << std::endl;
+ emit CaptureStartedSignal();
}
}
@@ -785,12 +863,13 @@ void SingleLensReflexCameraOperation::stopCapture()
{
m_captureTimer->stop();
std::cout << "Capture timer stopped" << std::endl;
+ emit CaptureStoppedSignal();
}
}
void SingleLensReflexCameraOperation::captureOnce()
{
- if (record)
+ if (m_isRecord)
{
QMutexLocker locker(&m_mutex);
takePicture();
@@ -803,22 +882,17 @@ void SingleLensReflexCameraOperation::CloseSLRCamera()
QMutexLocker locker(&m_mutex);
- record = false;
+ m_isRecord = false;
- // 停止拍照定时器
+ // 停止定时器
if (m_captureTimer != nullptr)
{
m_captureTimer->stop();
- delete m_captureTimer;
- m_captureTimer = nullptr;
}
- // 停止实时取景定时器
if (m_liveViewTimer != nullptr)
{
m_liveViewTimer->stop();
- delete m_liveViewTimer;
- m_liveViewTimer = nullptr;
}
// 停止实时取景
diff --git a/HPPA/SingleLensReflexCameraWindow.h b/HPPA/SingleLensReflexCameraWindow.h
index 4fcc603..63ad406 100644
--- a/HPPA/SingleLensReflexCameraWindow.h
+++ b/HPPA/SingleLensReflexCameraWindow.h
@@ -38,7 +38,7 @@ public:
QImage m_colorImage;
QImage m_depthImage;
void setCallback(void(*func)());
- bool getRecordStatus() const { return record; }
+ bool getRecordStatus() const { return m_isRecord; }
// 设置保存路径
void setSavePath(const QString& path);
@@ -49,7 +49,7 @@ public:
private:
cv::Mat frame;
func m_func;
- bool record;
+ bool m_isRecord;
// Canon EDSDK相关成员
EdsCameraRef m_camera;
@@ -90,6 +90,8 @@ private:
public slots:
void OpenSLRCamera();
+ void takePhoto();
+ void stopTakePhoto();
void OpenSLRCamera_callback();
void CloseSLRCamera();
void onCaptureTimer();
@@ -111,6 +113,9 @@ signals:
void LiveViewImageReady(const QImage& image);
void LiveViewStarted();
void LiveViewStopped();
+
+ void CaptureStartedSignal();
+ void CaptureStoppedSignal();
};
class SingleLensReflexCameraWindow : public QDialog
@@ -127,6 +132,8 @@ public Q_SLOTS:
void onSelectDataFolder();
void openSLRCamera();
+ void takePhoto();
+ void stopTakePhoto();
void onCamOpened();
void closeSLRCamera();
void onCamClosed();
@@ -138,8 +145,13 @@ public Q_SLOTS:
void onStopCapture();
void onCaptureOnce();
+ void onCaptureStarted();
+ void onCaptureStopped();
+
signals:
void openSLRCameraSignal();
+ void takePhotoSignal();
+ void stopTakePhotoSignal();
void closeSLRCameraSignal();
void PlotSLRImageSignal();
void SLRCamClosedSignal();
@@ -159,6 +171,8 @@ private:
// 用于显示实时取景的标签(如果UI中没有,可以动态创建)
QLabel* m_liveViewLabel;
+
+ QString m_btnOldText; // 存储拍照按钮的原始文本
bool m_isCapturing; // 是否正在定时拍照
};