-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencamera.h
71 lines (63 loc) · 1.51 KB
/
opencamera.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
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/videodev2.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <memory.h>
#define WIDTH 320 //320
#define HEIGHT 240 //240
#define DENOMINATOR 1 //1
#define NUMERATOR 25//25
typedef struct VideoBuffer{
__u8* start;
size_t length;
}VIDEOBUF;
class OpenCamera
{
private:
//capture device supported formats
void queryFomat();
fd_set rfds;
struct timeval ts; //该结构体用于描述一段时间长度
public:
//Used to create a frame queue
VIDEOBUF *vedio;
//device id
int vfd;
/* enum video type */
struct v4l2_fmtdesc fmtd;
//frame format
struct v4l2_frmsizeenum frmsize; //Max framesize
struct v4l2_format v4l2_fmt;
/* mmap buffer*/
struct v4l2_requestbuffers v4l2_reqbuf;
//a frame
struct v4l2_buffer buffer;
OpenCamera();
~OpenCamera();
//open the device file
bool openCam(char* device);
//init the camera
void camInit();
//get the frame from video buffer
int getFrame(__u8 *frame);
//
void saveImage(__u8* address, int length);
//close device and stop vedio stream
void closeCam();
};
//interface for "C"
#ifdef __cplusplus
extern "C"
{
#endif
extern void *construct_camera();
extern int camera_init(void *camera, char *devicename);
extern int get_frame(void *camera, __u8 * frame);
extern void destroy_camera(void *camera);
#ifdef __cplusplus
}
#endif