-
Notifications
You must be signed in to change notification settings - Fork 14
/
visionloc.cc
170 lines (148 loc) · 3.98 KB
/
visionloc.cc
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <unistd.h>
#include <vector>
#include <stdexcept>
#include <opencv2/core/core.hpp>
#include "camera.hh"
#include "misc.hh"
#include <iostream>
double out[256];
int tag;
std::vector<Camera> cameras;
extern "C"
void start_visionloc()
{
parser_xml_to_cameras(&cameras);
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
sleep(1);
it->run();
}
}
extern "C"
void stop_visionloc()
{
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it) {
it->stop();
}
cameras.clear();
}
extern "C"
double* read_camera(int num_camera)
{
int j = 0;
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
if(it->get_id_cam() == num_camera)
{
//int num_recog;
std::vector<Marker> m(it->get_markers());
out[j++] = it->get_id_cam();
out[j++] = m.size();
for (std::vector<Marker>::iterator itm = m.begin(); itm != m.end(); ++itm){
out[j++] = itm->id;
out[j++] = itm->cam_corner_posX;
out[j++] = itm->cam_corner_posY;
out[j++] = itm->cam_center_posX;
out[j++] = itm->cam_center_posY;
out[j++] = itm->cam_heading;
}
break;
}
}
return out;
}
extern "C"
double* read_all_cameras()
{
int j = 0;
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
//int num_recog;
std::vector<Marker> m(it->get_markers());
out[j++] = it->get_id_cam();
out[j++] = m.size();
for (std::vector<Marker>::iterator itm = m.begin(); itm != m.end(); ++itm){
out[j++] = itm->id;
out[j++] = itm->cam_corner_posX;
out[j++] = itm->cam_corner_posY;
out[j++] = itm->cam_center_posX;
out[j++] = itm->cam_center_posY;
out[j++] = itm->cam_heading;
}
}
return out;
}
extern "C"
int get_tag(int num_camera)
{
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
if(it->get_id_cam() == num_camera)
{
return it->get_tag();
}
}
return -1;
}
extern "C"
int set_expected_num_of_markers(int num_camera, int num_markers)
{
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
if(it->get_id_cam() == num_camera)
{
it->set_expected_num_of_markers(num_markers);
return 0;
}
}
return -1;
}
extern "C" int get_cam_width(int num_camera)
{
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
if(it->get_id_cam() == num_camera)
{
return it->get_width();
}
}
return -1;
}
extern "C" int get_cam_height(int num_camera)
{
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
if(it->get_id_cam() == num_camera)
{
return it->get_height();
}
}
return -1;
}
std::vector<int> get_active_cameras(void)
{
std::vector<int> cam_ids;
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
cam_ids.push_back(it->get_id_cam());
}
return cam_ids;
}
std::vector<Marker> get_markers_from_camera(int num_camera)
{
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
if(it->get_id_cam() == num_camera)
return it->get_markers();
}
throw std::invalid_argument("get_markers_from_camera: camera not found");
}
cv::Mat* get_frame_from_camera(int num_camera)
{
for (std::vector<Camera>::iterator it = cameras.begin() ; it != cameras.end(); ++it)
{
if(it->get_id_cam() == num_camera)
return it->get_frame();
}
throw std::invalid_argument("get_frame_fromcamera not found");
}