-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCameraManager.cpp
More file actions
147 lines (116 loc) · 3.31 KB
/
CameraManager.cpp
File metadata and controls
147 lines (116 loc) · 3.31 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "CameraManager.h"
#include "CameraController.h"
CameraMan* CameraMan::_instance = NULL;
CameraMan::CameraMan()
{
_getCameralist = false;
}
CameraMan::~CameraMan()
{
}
void CameraMan::enumCameraList()
{
if (_getCameralist == false)
{
cameraIDlist.clear();
//////////////////////////////////////////////////////////////////////////
Camera* camera = NULL;
GPContext* context = NULL;
GPPortInfoList* portinfo_list = NULL;
CameraAbilitiesList* _abilities_list = NULL;
gp_camera_new(&camera);
context = gp_context_new();
//gp_context_set_error_func(context, (GPContextErrorFunc)Camera_Context::_error_callback, NULL);
//gp_context_set_status_func(context, (GPContextMessageFunc)Camera_Context::_message_callback, NULL);
int ret = gp_camera_init(camera, context);
if (ret < GP_OK)
gp_camera_free(camera);
//////////////////////////////////////////////////////////////////////////
int count, result;
if (gp_port_info_list_new(&portinfo_list) < GP_OK)
return;
result = gp_port_info_list_load(portinfo_list);
if (result < 0)
{
gp_port_info_list_free(portinfo_list);
return;
}
count = gp_port_info_list_count(portinfo_list);
if (count < 0)
{
gp_port_info_list_free(portinfo_list);
return;
}
GPPortInfo info;
for (int x = 0; x < count; x++)
{
char* xname, * xpath;
result = gp_port_info_list_get_info(portinfo_list, x, &info);
if (result < 0)
break;
gp_port_info_get_name(info, &xname);
gp_port_info_get_path(info, &xpath);
printf("%-32s %-32s\n", xpath, xname);
}
//////////////////////////////////////////////////////////////////////////
{
const char* name = NULL, * value = NULL;
CameraList* list;
gp_list_new(&list);
gp_abilities_list_detect(gp_params_abilities_list(context, _abilities_list), portinfo_list, list, context);
int count = gp_list_count(list);
printf("%-30s %-16s\n", "Model", "Port");
printf("----------------------------------------------------------\n");
for (int x = 0; x < count; x++)
{
gp_list_get_name(list, x, &name);
gp_list_get_value(list, x, &value);
printf("%-30s %-16s\n", name, value);
cameraIDlist.push_back(std::string(value));
}
gp_list_free(list);
}
if(camera != NULL)
gp_camera_exit(camera, context);
if( context != NULL )
gp_context_unref(context);
if (portinfo_list != NULL)
gp_port_info_list_free(portinfo_list);
if (portinfo_list != NULL)
gp_abilities_list_free(_abilities_list);
_getCameralist = true;
}
// create all cameras
if (_getCameralist)
{
for (int i=0; i< cameraIDlist.size(); i++)
{
CameraController* camera = new CameraController();
camera->init();
camera->setPort(cameraIDlist[i]);
cameraList.push_back(camera);
}
}
}
CameraAbilitiesList* CameraMan::gp_params_abilities_list(GPContext* context, CameraAbilitiesList* _abilities_list)
{
/* If p == NULL, the behaviour of this function is as undefined as
* the expression p->abilities_list would have been. */
if (_abilities_list == NULL)
{
gp_abilities_list_new(&_abilities_list);
gp_abilities_list_load(_abilities_list, context);
}
return _abilities_list;
}
// °¹¼ö
int CameraMan::getEnumCameraNum()
{
return cameraIDlist.size();
}
CameraController* CameraMan::getCamera(int i)
{
if (cameraList.size() <= i)
return NULL;
return cameraList[i];
}