-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.h
More file actions
123 lines (85 loc) · 3.21 KB
/
camera.h
File metadata and controls
123 lines (85 loc) · 3.21 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*! @file camera.h
* @brief Camera Class
* All Pictures are aligned to PICTURE_ALIGNMENT
*/
#ifndef CAMERA_H_
#define CAMERA_H_
#include <leancv.h>
#include "includes.h"
#define REG_AEC_AGC_ENABLE 0xAF
/* @brief struct ROI. Region of Interest, default values are for the whole picture */
struct ROI {
ROI(uint16 low_x=0, uint16 low_y=0, uint16 width=OSC_CAM_MAX_IMAGE_WIDTH, uint16 height=OSC_CAM_MAX_IMAGE_HEIGHT)
: low_x(low_x), low_y(low_y), width(width), height(height) {}
uint16 low_x;
uint16 low_y;
uint16 width;
uint16 height;
};
enum ColorType {
ColorType_none, // No valid image yet
ColorType_gray, // Image from a grayscale sensor
ColorType_raw, // Raw image from a color sensor
ColorType_debayered // Debayered image from a color sensor
};
#define PICTURE_ALIGNMENT LCV_IMG_ALIGN
class CCamera {
public:
CCamera();
~CCamera();
/*! @brief Initializes the camera module
* NOTE: Oscar Framework must be initialized before this call!
*/
OSC_ERR Init(const ROI& region_of_interest, uint8 buffer_count=2
, EnOscCamPerspective perspective=OSC_CAM_PERSPECTIVE_DEFAULT);
/*! @brief get the latest picture and do debayering if needed
* returns the image or NULL on error
* Picture is aligned to PICTURE_ALIGNMENT
*/
IplImage* ReadLatestPicture();
/*! @brief Read the current captured picture.
* like ReadLatestPicture, but waits for image to be captured
* call CapturePicture and ReadPicture if you want the most actual picture
*/
IplImage* ReadPicture(uint16 max_age=0, uint16 timeout=0);
/*! @brief setup a capture an return immediately */
OSC_ERR CapturePicture();
/*! @brief get region of interest */
const ROI& getROI() const { return(m_roi); }
void setROI(const ROI& new_roi) {
m_roi=new_roi; m_bRoi_changed=true;
OscCamSetAreaOfInterest(m_roi.low_x, m_roi.low_y, m_roi.width, m_roi.height);
}
ColorType getColorType() { return(m_color_type); }
void setColorType(ColorType type) { m_color_type=type; }
/*! @brief getAppropriateColorType: returns color type depending on hardware: either gray or color */
ColorType getAppropriateColorType();
EnOscCamPerspective getPerspective() { return(m_perspective); }
void setPerspective(EnOscCamPerspective perspective) {
m_perspective=perspective;
OscCamSetupPerspective(m_perspective);
}
void setAutoExposure(bool bEnabled);
bool getAutoExposure() const;
/*! @brief Align an image pointer to a multiple of PICTURE_ALIGNMENT
* IMPORTANT: make sure, pic is PICTURE_ALIGNMENT bytes larger than needed!
* Note: OpenCV needs aligned pictures
*/
static uint8* AlignPicture(const uint8* pic);
static uint32 AlignSize(uint32 size);
private:
IplImage* HandlePictureColoringAndSize(uint8* pic_data);
/* set new imageheader if channel_count is not the same or size is not same as from camera */
void AdjustImageHeader(IplImage** img, int channel_count);
IplImage* m_img;
uint8* m_img_data;
uint8* m_al_img_data; /*! @brief aligned pointer to m_img_data */
uint8* m_frame_buffer_ids;
uint8_t* m_frame_buffers;
ROI m_roi;
bool m_bRoi_changed; /* if true, m_img header must be reinitialized */
int m_buffer_count;
ColorType m_color_type;
EnOscCamPerspective m_perspective;
};
#endif /* CAMERA_H_ */