-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
63 lines (51 loc) · 1.62 KB
/
mainwindow.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
54
55
56
57
58
59
60
61
62
63
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(onNewImage()));
// Create a PXCSenseManager instance
sm = PXCSenseManager::CreateInstance();
// Select the color stream
sm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH,640,480);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onNewImage()
{
if (sm->AcquireFrame(true)<PXC_STATUS_NO_ERROR)
return;
// retrieve the sample
PXCCapture::Sample *sample=sm->QuerySample();
//image is a PXCImage instance
PXCImage::ImageData depthData;
sample->depth->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::PIXEL_FORMAT_RGB32, &depthData);
int height = sample->depth->QueryInfo().height;
int width= sample->depth->QueryInfo().width;
// image planes are in data.planes[0-3] with pitch data.pitches[0-3]
QImage depthImage(depthData.planes[0],width, height,QImage::Format_RGB32);
sample->depth->ReleaseAccess(&depthData);
ui->colorImage->setPixmap( QPixmap::fromImage(depthImage).scaled(width,height,Qt::KeepAspectRatio));
// go fetching the next sample
sm->ReleaseFrame();
}
void MainWindow::onStart()
{
sm->Init();
timer->start(1000/24);
this->ui->startButton->setEnabled(false);
this->ui->stopButton->setEnabled(true);
}
void MainWindow::onStop()
{
timer->stop();
sm->Release();
this->ui->startButton->setEnabled(true);
this->ui->stopButton->setEnabled(false);
}