-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreflexcam.cpp
More file actions
68 lines (58 loc) · 1.49 KB
/
reflexcam.cpp
File metadata and controls
68 lines (58 loc) · 1.49 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
#include <fcntl.h>
#include <iostream>
#include "reflexcam.h"
ReflexCam::ReflexCam() : cam(nullptr), context(nullptr)
{
int error;
error = gp_camera_new(&this->cam);
if (error != GP_OK)
{
this->accessable = false;
return;
}
this->context = gp_context_new();
if (this->context == nullptr)
{
this->accessable = false;
return;
}
error = gp_camera_init(this->cam, this->context);
if (error != GP_OK) {
gp_camera_free(this->cam);
this->cam = nullptr;
this->accessable = false;
}
else
{
this->accessable = true;
}
}
bool ReflexCam::getImage(cv::Mat& mat)
{
const char filename[] = "temp";
CameraFile* file;
CameraFilePath camera_file_path;
// TODO: what happens if camera is deconnected mid process?
gp_camera_capture(cam, GP_CAPTURE_IMAGE, &camera_file_path, this->context);
int fd = open(filename, O_CREAT | O_WRONLY, 0644);
gp_file_new_from_fd(&file, fd);
gp_camera_file_get(this->cam, camera_file_path.folder, camera_file_path.name, GP_FILE_TYPE_NORMAL, file, this->context);
gp_camera_file_delete(this->cam, camera_file_path.folder, camera_file_path.name, this->context);
mat = cv::imread(filename);
if (mat.empty())
{
return false;
}
return true;
}
ReflexCam::~ReflexCam()
{
if (this->context)
{
gp_context_unref(this->context);
}
if (this->cam)
{
gp_camera_unref(this->cam);
}
}