-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera_API_version.cpp
More file actions
59 lines (43 loc) · 1.68 KB
/
Copy pathcamera_API_version.cpp
File metadata and controls
59 lines (43 loc) · 1.68 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
#include "camera.h"
StarCamera::StarCamera(int exposure, int res_row, int res_col, int iso):
_exposure(exposure), _res_row(res_row), _res_col(res_col), _iso(iso) {
// Values set. Anything else?
}
//iso is light sensitivity, exposure is time, resolution is max image size we can use
//init camera, assign settings
void StarCamera::init() {
cam_man.start(); // Initialize the camera from libcam
if (cam_man.cameras().empty()) {
std::cerr << "No cameras found\n";
}
camera = cam_man.cameras()[0];
camera->acquire();
config = camera->generateConfiguration({StreamRole::StillCapture});
if (!config || config->empty()) {
std::cerr << "Failed to get config\n";
}
config->at(0).pixelFormat = formats::RGB888;
config->at(0).size = {MAX_WIDTH, MAX_HEIGHT};
config->validate();
camera->configure(config.get());
allocator = std::make_unique<FrameBufferAllocator>(camera);
stream = config->at(0).stream();
if (allocator->allocate(stream) < 0) {
std::cerr << "Buffer allocation failed\n";
}
const std::vector<std::unique_ptr<FrameBuffer>> &buffer = allocator->buffers(stream);
fb = buffer[0].get();
}
//take picture, when SPI commands picture, this will be called to take image
bool StarCamera::take_picture() {
auto request = camera->createRequest();
if (!request) {
return false;
}
if (request->addBuffer(stream, fb) < 0) return false;
if (camera->queueRequest(request) < 0) return false;
request->wa
}
//see pictire, when SPI wants raw image data, this will export raw image data
void print_picture();
//send picture