-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
54 lines (43 loc) · 1.58 KB
/
Copy pathCamera.cpp
File metadata and controls
54 lines (43 loc) · 1.58 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
#include "Camera.h"
bool Camera::isOpened() {
return this->capture.isOpened();
}
int Camera::getWidth() {
return static_cast<int>(this->capture.get(cv::CAP_PROP_FRAME_WIDTH));
}
int Camera::getHeight() {
return static_cast<int>(this->capture.get(cv::CAP_PROP_FRAME_HEIGHT));
}
void Camera::read(cv::OutputArray image) {
if (this->capture.isOpened()) {
this->capture.read(image);
cv::flip(image, image, 1);
}
}
void Camera::analyse(cv::Mat image, std::vector<FaceInfo> &backup) {
if (!image.empty()) {
this->face_info = std::vector<FaceInfo>();
this->centerface.detect(image, this->face_info);
backup = this->face_info;
Sleep(25); // /!\ reduce CPU utilization
}
this->analysing = false;
}
void Camera::release() {
this->capture.release();
}
Camera::Camera() {}
Camera::Camera(int camera_id, std::string model_path) {
this->capture = cv::VideoCapture(camera_id, cv::CAP_DSHOW);
this->capture.set(cv::CAP_PROP_FRAME_WIDTH, 1920);
this->capture.set(cv::CAP_PROP_FRAME_HEIGHT, 1080);
this->capture.set(cv::CAP_PROP_FPS, 60);
this->capture.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));
std::cout << this->capture.get(cv::CAP_PROP_FRAME_WIDTH) << "x" << this->capture.get(cv::CAP_PROP_FRAME_HEIGHT) << " " << this->capture.get(cv::CAP_PROP_FPS) << " fps" << std::endl;
this->centerface = Centerface(model_path, this->getWidth() / 4, this->getHeight() / 4);
}
Camera::Camera(Camera& camera) {
this->capture = camera.capture;
this->centerface = camera.centerface;
this->face_info = camera.face_info;
}