-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraManager.cpp
More file actions
48 lines (39 loc) · 1.42 KB
/
Copy pathCameraManager.cpp
File metadata and controls
48 lines (39 loc) · 1.42 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
#include "CameraManager.hpp"
#include <iostream>
CameraManager::CameraManager(int index)
: cameraIndex(index), roiRect(100, 50, 440, 380)
{}
CameraManager::~CameraManager() {
stop();
}
void CameraManager::startCapture(FrameCallback callback) {
userCallback = std::move(callback);
// Register lambda as the frame callback (OnFrame = std::function).
// The kernel wakes the libcamera thread via blocking I/O on the V4L2
// media-controller fd whenever the sensor delivers a complete frame.
camera.registerCallback([this](const cv::Mat& frame,
const libcamera::ControlList&) {
if (!userCallback) return;
const cv::Rect& r = roiRect;
cv::Mat roi;
if (r.x + r.width <= frame.cols &&
r.y + r.height <= frame.rows)
roi = frame(r).clone();
else
roi = frame.clone();
// Invoking userCallback wakes the consumer thread blocked on
// condition_variable::wait() in main — hardware-event-driven chain.
userCallback(roi);
});
Libcam2OpenCVSettings settings;
settings.cameraIndex = static_cast<unsigned int>(cameraIndex);
settings.width = 640;
settings.height = 480;
settings.framerate = 30;
cm.start();
camera.start(cm, settings);
}
void CameraManager::stop() {
camera.stop();
cm.stop();
}