-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenericCamera.cpp
59 lines (42 loc) · 1.46 KB
/
GenericCamera.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
/*---------------------------------------------------------------------------*\
This program is free software. It comes without any warranty, to the extent
permitted by applicable law. You can redistribute it and/or modify it under
the terms of the Do What The Fuck You Want To Public License, Version 2, as
published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
Copyright © 2014 Luiz Gustavo M. Sampaio www.lgmsampaio.com
\*---------------------------------------------------------------------------*/
#include "GenericCamera.h"
using namespace std;
using namespace cv;
// Implementation of Generic Camera class, connecting usually builtin cameras
GenericCamera::GenericCamera(int frameW, int frameH, int deviceId,
char* deviceName)
{
type = SourceType::CAM_GENERIC;
this->deviceName = deviceName;
// Will get the first camera available (if any)
//cap = VideoCapture(CV_CAP_ANY);
cap = VideoCapture(deviceId);
if(frameW > 0 && frameH > 0){
cap.set(CV_CAP_PROP_FRAME_WIDTH, frameW);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, frameH);
}
}
GenericCamera::~GenericCamera(void)
{
cap.release();
cout << "capture finished" << endl;
}
bool GenericCamera::isConnected()
{
return cap.isOpened();
}
Mat GenericCamera::getNextImage()
{
Mat frame;
cap >> frame;
// Some cameras take more time to start to deliver images, so we need to
// wait until we get some data before return it to "outside"
while(frame.empty()) cap >> frame;
return frame;
}