| 136 | |
| 137 | |
| 138 | box_label *read_boxes(char *filename, int *n) |
| 139 | { |
| 140 | FILE *file = fopen(filename, "r"); |
| 141 | if(!file) file_error(filename); |
| 142 | float x, y, h, w; |
| 143 | int id; |
| 144 | int count = 0; |
| 145 | int size = 64; |
| 146 | box_label *boxes = calloc(size, sizeof(box_label)); |
| 147 | while(fscanf(file, "%d %f %f %f %f", &id, &x, &y, &w, &h) == 5){ |
| 148 | if(count == size) { |
| 149 | size = size * 2; |
| 150 | boxes = realloc(boxes, size*sizeof(box_label)); |
| 151 | } |
| 152 | boxes[count].id = id; |
| 153 | boxes[count].x = x; |
| 154 | boxes[count].y = y; |
| 155 | boxes[count].h = h; |
| 156 | boxes[count].w = w; |
| 157 | boxes[count].left = x - w/2; |
| 158 | boxes[count].right = x + w/2; |
| 159 | boxes[count].top = y - h/2; |
| 160 | boxes[count].bottom = y + h/2; |
| 161 | ++count; |
| 162 | } |
| 163 | fclose(file); |
| 164 | *n = count; |
| 165 | return boxes; |
| 166 | } |
| 167 | |
| 168 | void randomize_boxes(box_label *b, int n) |
| 169 | { |
no test coverage detected