-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcamera.cpp
executable file
·71 lines (55 loc) · 1.7 KB
/
camera.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
64
65
66
67
68
69
#include "camera.h"
Camera::Camera(MainWindow * p_mainWindow) :
m_cameraCapture(0)
{
qDebug("Camera::Camera(MainWindow * p_mainWindow)");
this->m_mainWindow = p_mainWindow;
connect(&(this->m_timer), SIGNAL(timeout()), this, SLOT(captureImage()));
}
Camera::~Camera()
{
qDebug("Camera::~Camera()");
if (this->m_cameraCapture)
this->disconnect();;
}
bool Camera::connectCamera(int p_deviceNumber)
{
qDebug("Camera::connectCamera(int %i)", p_deviceNumber);
if (this->m_cameraCapture)
this->disconnect();
this->m_mainWindow->log("Starting webcam number <strong>" + QString::number(p_deviceNumber) + "</strong>");
this->m_cameraCapture = cvCreateCameraCapture(p_deviceNumber);
if (!this->m_cameraCapture)
{
this->m_mainWindow->logError("Webcam not connected !");
QMessageBox::critical(this->m_mainWindow, "TouchCar - Webcam", "Webcam not connected !");
return false;
}
this->m_timer.start(80);
return true;
}
void Camera::disconnect()
{
qDebug("Camera::disconnect()");
if (this->m_timer.isActive())
this->m_timer.stop();
if (this->m_cameraCapture)
{
this->m_mainWindow->log("Shutdown webcam...");
cvReleaseCapture(&(this->m_cameraCapture));
}
}
void Camera::captureImage()
{
qDebug("Camera::captureImage()");
if (!this->m_cameraCapture)
return;
QTime timer;
timer.start();
IplImage *iplImage = cvQueryFrame(this->m_cameraCapture);
uchar *data;
QImage *qImg = IplImageToQImage(iplImage, &data);
this->m_mainWindow->setCameraFrame(*qImg);
this->m_mainWindow->setCaptureTime(timer.elapsed());
//qDebug("did in %i ms", timer.elapsed());
}