-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcameradevice.cpp
57 lines (40 loc) · 1.01 KB
/
cameradevice.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
#include "cameradevice.hpp"
videoInput CameraDevice::vi;
CameraDevice::CameraDevice(int id){
this->id = id;
this->img = NULL;
}
CameraDevice::~CameraDevice(){
stop();
if(img) cvReleaseImage(&img);
}
bool CameraDevice::init(){
vi.setupDevice(id);
if(!vi.isDeviceSetup(id))
return false;
this->width = vi.getWidth(id);
this->height = vi.getHeight(id);
vi.setIdealFramerate(id, 40);
img = cvCreateImage(cvSize(width, height), 8, 3);
return true;
}
bool CameraDevice::init(int width, int height){
this->width = width;
this->height = height;
vi.setupDevice(id, width, height);
if(!vi.isDeviceSetup(id))
return false;
vi.setIdealFramerate(id, 40);
img = cvCreateImage(cvSize(width, height), 8, 3);
return true;
}
void CameraDevice::stop(){
vi.stopDevice(id);
}
IplImage * CameraDevice::getNextFrame(){
vi.getPixels(id, (unsigned char *)img->imageData, false, true);
return img;
}
bool CameraDevice::hasNextFrame(){
return vi.isFrameNew(id);
}