-
Notifications
You must be signed in to change notification settings - Fork 0
/
cameraworker.cpp
53 lines (41 loc) · 1.55 KB
/
cameraworker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <QDebug>
#include <QFile>
#include <string.h>
#include "clog.h"
#include "cameraworker.h"
CameraWorker::CameraWorker()
{
m_previewProcess = new QProcess(this);
connect(m_previewProcess, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus){ capturePhotoEnd();});
}
CameraWorker::~CameraWorker()
{
}
void CameraWorker::startPreview(const QString &fileName, int previewX, int previewY, int previewWidth, int previewHeight)
{
if (!m_previewProcess->isOpen()) {
currentFilename = fileName;
QString program = "raspistill";
QStringList arguments;
if (previewX != CAMERA_PREVIEW_X || previewY != CAMERA_PREVIEW_Y || previewWidth != CAMERA_PREVIEW_WIDTH || previewHeight != CAMERA_PREVIEW_HEIGHT) {
arguments << "--preview" << QString::number(previewX) + ',' + QString::number(previewY) + ',' + QString::number(previewWidth) + ',' + QString::number(previewHeight);
}
arguments << "-h" << QString::number(CAMERA_HEIGHT) << "-w" << QString::number(CAMERA_WIDTH)
<< "-k" << "-o" << fileName;
m_previewProcess->start(program, arguments);
}
}
void CameraWorker::capturePhoto()
{
//Capture photo and end process by sending x to input chanel
if (m_previewProcess->isOpen()) {
m_previewProcess->write("x\n");
//m_previewProcess->closeWriteChannel();
}
}
void CameraWorker::capturePhotoEnd()
{
m_previewProcess->close();
emit imageCaptured(currentFilename);
}