-
Notifications
You must be signed in to change notification settings - Fork 7
/
cap.h
60 lines (50 loc) · 1000 Bytes
/
cap.h
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
/**
* A simple warpper for Capture in C++.
*
* @blackball
*/
#ifndef CV_CAP_H
#define CV_CAP_H
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
class Capture {
public:
Capture() : m_cap(0){}
~Capture() {
_release();
}
void open_cam(void) { _release(); m_cap = cvCaptureFromCAM(0);}
void open(int device) {
_release();
m_cap = cvCaptureFromCAM(device);
if (!m_cap) {
fprintf(stderr, "Can not open camera device: %s\s!\n", device);
exit(0);
}
}
void open(const char *vname) {
_release();
m_cap = cvCaptureFromFile(vname);
if (!m_cap) {
fprintf(stderr, "Can not open video: %s!\n", vname);
exit(0);
}
}
int grab() {
return cvGrabFrame(m_cap);
}
IplImage * retrieve() {
return cvRetrieveFrame(m_cap);
}
IplImage * queryFrame() {
return cvQueryFrame(m_cap);
}
private:
void _release() {
cvReleaseCapture( &m_cap );
}
private:
CvCapture *m_cap;
};
#endif