Revision 466
fixed vision bug
trunk/code/projects/colonet/vision/vision_driver.c | ||
---|---|---|
9 | 9 |
int main(int argc, char** argv) { |
10 | 10 |
const char* filename = (argc == 2) ? argv[1] : (char*)"colonet.jpg"; |
11 | 11 |
|
12 |
printf("vision_init(%s)\n", filename); |
|
13 |
|
|
12 | 14 |
if (vision_init(filename) != 0) { |
13 | 15 |
fprintf(stderr, "init_vision failed.\n"); |
14 | 16 |
return -1; |
17 |
} else { |
|
18 |
fprintf(stderr, "vision_init succeeded.\n"); |
|
15 | 19 |
} |
16 | 20 |
|
17 | 21 |
VisionPosition* positions; |
18 | 22 |
int num_positions = vision_get_robot_positions(&positions); |
19 | 23 |
|
24 |
printf("Got %d positions.\n", num_positions); |
|
25 |
|
|
20 | 26 |
int i; |
21 | 27 |
for (i = 0; i < num_positions; i++) { |
22 | 28 |
printf("%d,%d\n", positions[i].x, positions[i].y); |
trunk/code/projects/colonet/vision/vision.c | ||
---|---|---|
127 | 127 |
found=1; |
128 | 128 |
break; |
129 | 129 |
} |
130 |
}
|
|
130 |
}
|
|
131 | 131 |
|
132 | 132 |
if (!found){ |
133 | 133 |
struct CenterP c; |
... | ... | |
148 | 148 |
image04 = cvCloneImage(image03); |
149 | 149 |
|
150 | 150 |
int count = 0; |
151 |
|
|
152 | 151 |
int i; |
153 | 152 |
for (i = 0; i < index; i++) { |
154 | 153 |
if (bestc[i].count > 7){ |
... | ... | |
156 | 155 |
} |
157 | 156 |
} |
158 | 157 |
|
159 |
VisionPosition* pos = (VisionPosition*)malloc(sizeof(VisionPosition) * count); |
|
158 |
VisionPosition* pos_array = (VisionPosition*)malloc(sizeof(VisionPosition) * count); |
|
159 |
if (pos_array == NULL) { |
|
160 |
fprintf(stderr, "malloc failed\n"); |
|
161 |
return -1; |
|
162 |
} |
|
163 |
|
|
164 |
int c = 0; |
|
160 | 165 |
for (i = 0; i < index; i++) { |
161 | 166 |
if (bestc[i].count > 7){ |
162 |
pos[i].x = bestc[i].center.x; |
|
163 |
pos[i].y = bestc[i].center.y; |
|
167 |
pos_array[c].x = bestc[i].center.x; |
|
168 |
pos_array[c].y = bestc[i].center.y; |
|
169 |
c++; |
|
164 | 170 |
|
165 |
if (DEBUG) cvCircle(image04,bestc[i].center, 20, CV_RGB(0,0,0),5,8,0);
|
|
171 |
if (DEBUG) cvCircle(image04, bestc[i].center, 20, CV_RGB(0,0,0), 5, 8, 0);
|
|
166 | 172 |
} |
167 | 173 |
} |
168 | 174 |
|
169 | 175 |
// Show image. HighGUI use. |
170 | 176 |
if (DEBUG) cvShowImage( "Result", image04 ); |
171 | 177 |
|
172 |
*positions = pos; |
|
178 |
*positions = pos_array;
|
|
173 | 179 |
return count; |
174 | 180 |
} |
trunk/code/projects/colonet/vision/Makefile | ||
---|---|---|
6 | 6 |
|
7 | 7 |
vision: |
8 | 8 |
$(CC) -ggdb `pkg-config opencv --cflags --libs` -c -I . vision.c |
9 |
|
|
9 |
|
|
10 | 10 |
vision_driver: vision |
11 |
$(CC) -ggdb `pkg-config opencv --cflags --libs` -I . vision_driver.c vision.o -o vision_driver |
|
11 |
$(CC) -ggdb `pkg-config opencv --cflags --libs` -g -I . vision_driver.c vision.o -o vision_driver
|
|
12 | 12 |
|
13 | 13 |
fitellipse: |
14 | 14 |
$(CC) -ggdb `pkg-config opencv --cflags --libs` fitellipse.c -o fitellipse |
trunk/code/projects/colonet/ColonetServer/Command.cpp | ||
---|---|---|
282 | 282 |
} |
283 | 283 |
|
284 | 284 |
int Command::parse_request_robot_positions(int pool_index) { |
285 |
printf("parse_request_robot_positions\n"); |
|
285 |
printf("*****parse_request_robot_positions\n");
|
|
286 | 286 |
|
287 | 287 |
map<int, VisionPosition> positions = colonet_server->getPositionMonitor()->getAllRobotPositions(); |
288 | 288 |
map<int, VisionPosition>::iterator iter; |
289 | 289 |
|
290 |
char position_buffer[256] = ""; |
|
290 |
char position_buffer[256]; |
|
291 |
position_buffer[0] = 0; |
|
292 |
sprintf(position_buffer, "%d %d", RESPONSE_TO_CLIENT_REQUEST, CLIENT_REQUEST_ROBOT_POSITIONS); |
|
293 |
|
|
291 | 294 |
for (iter = positions.begin(); iter != positions.end(); iter++) { |
292 | 295 |
char tmpbuf[80]; |
293 |
sprintf(tmpbuf, "%d %d %d ", iter->first, iter->second.x, iter->second.y);
|
|
296 |
sprintf(tmpbuf, " %d %d %d", iter->first, iter->second.x, iter->second.y);
|
|
294 | 297 |
strcat(position_buffer, tmpbuf); |
295 | 298 |
} |
296 | 299 |
|
300 |
strcat(position_buffer, "\n"); |
|
301 |
|
|
302 |
printf("position buffer is: %s\n", position_buffer); |
|
303 |
|
|
297 | 304 |
connection_pool->write_to_client(pool_index, position_buffer, strlen(position_buffer)); |
298 | 305 |
|
299 | 306 |
return 0; |
trunk/code/projects/colonet/ColonetServer/PositionMonitor.cpp | ||
---|---|---|
21 | 21 |
//TODO: don't hardcode this file name |
22 | 22 |
//TODO: check for error returned from init |
23 | 23 |
vision_init("/var/www/colonet.jpg"); |
24 |
newIdToAssign = 0;
|
|
24 |
newIdToAssign = -1;
|
|
25 | 25 |
} |
26 | 26 |
|
27 | 27 |
PositionMonitor::~PositionMonitor() { |
... | ... | |
42 | 42 |
|
43 | 43 |
//TODO: check for error returned |
44 | 44 |
int numPositions = vision_get_robot_positions(&positions); |
45 |
printf("numPositions is %d\n", numPositions); |
|
45 | 46 |
|
46 | 47 |
/* |
47 | 48 |
//TODO: compare current set of positions to previous set of |
... | ... | |
55 | 56 |
positionMap[i] = positions[i]; |
56 | 57 |
} |
57 | 58 |
*/ |
58 |
|
|
59 |
|
|
59 | 60 |
//TODO: also remove robots that might have disappeared |
60 | 61 |
int i; |
61 | 62 |
for (i = 0; i < numPositions; i++) { |
... | ... | |
65 | 66 |
VisionPosition oldPos = iter->second; |
66 | 67 |
|
67 | 68 |
if (isProbablySameRobot(newPos, oldPos)) { |
68 |
//TODO: is this the right use of an iterator?
|
|
69 |
iter->second = newPos;
|
|
70 |
break;
|
|
69 |
//TODO: is this the right use of an iterator?
|
|
70 |
iter->second = newPos;
|
|
71 |
break;
|
|
71 | 72 |
} |
72 | 73 |
} |
73 |
|
|
74 |
|
|
74 | 75 |
if (iter == positionMap.end()) { |
76 |
printf("Inserting new robot: %d (%d,%d)", newIdToAssign, newPos.x, newPos.y); |
|
77 |
|
|
75 | 78 |
//a position was found that probably isn't a known robot so add it in case a new robot entered the field |
76 | 79 |
positionMap.insert(make_pair(newIdToAssign, newPos)); |
77 |
newIdToAssign++;
|
|
80 |
newIdToAssign--;
|
|
78 | 81 |
} |
79 | 82 |
} |
80 | 83 |
|
... | ... | |
107 | 110 |
} |
108 | 111 |
|
109 | 112 |
map<int, VisionPosition> PositionMonitor::getAllRobotPositions() { |
113 |
//TODO do this in another thread! |
|
114 |
updatePositions(); |
|
115 |
|
|
110 | 116 |
return positionMap; |
111 | 117 |
} |
112 | 118 |
|
Also available in: Unified diff