40 uint16_t labels_size = *labels_count;
46 for (i = 0; i < output->
w; i++) {
52 for (y = 1; y < input->
h; y++) {
53 for (x = 0; x < input->
w / 2; x++) {
55 uint8_t p_y = (input_buf[y * input->
w * 2 + x * 4 + 1] + input_buf[y * input->
w * 2 + x * 4 + 3]) / 2;
56 uint8_t p_u = input_buf[y * input->
w * 2 + x * 4];
57 uint8_t p_v = input_buf[y * input->
w * 2 + x * 4 + 2];
61 for (;
f < filters_cnt;
f++) {
70 if (
f >= filters_cnt) {
71 output_buf[y * output->
w + x] = 0xFFFF;
76 lid = output_buf[(y - 1) * output->
w + x];
77 if (y > 0 && lid < labels_size && labels[lid].filter ==
f) {
78 output_buf[y * output->
w + x] = lid;
80 labels[lid].
x_sum += x;
81 labels[lid].
y_sum += y;
86 lid = output_buf[(y - 1) * output->
w + x + 1];
87 if (y > 0 && x < output->w - 1 && lid < labels_size && labels[lid].filter ==
f) {
90 uint16_t lid_tl = output_buf[(y - 1) * output->
w + x - 1];
91 uint16_t lid_l = output_buf[y * output->
w + x - 1];
93 if (x > 0 && lid_tl < labels_size && labels[lid_tl].filter ==
f) {
96 n = labels[lid_tl].
id;
97 }
else if (x > 0 && lid_l < labels_size && labels[lid_l].filter ==
f) {
100 n = labels[lid_l].
id;
110 for (i = 0; i < labels_cnt; i++) {
111 if (labels[i].
id == n) {
118 output_buf[y * output->
w + x] = lid;
120 labels[lid].
x_sum += x;
121 labels[lid].
y_sum += y;
126 lid = output_buf[(y - 1) * output->
w + x - 1];
127 if (y > 0 && x > 0 && lid < labels_size && labels[lid].filter ==
f) {
128 output_buf[y * output->
w + x] = lid;
130 labels[lid].
x_sum += x;
131 labels[lid].
y_sum += y;
136 lid = output_buf[y * output->
w + x - 1];
137 if (x > 0 && lid < labels_size && labels[lid].filter ==
f) {
138 output_buf[y * output->
w + x] = lid;
140 labels[lid].
x_sum += x;
141 labels[lid].
y_sum += y;
146 if (labels_cnt >= labels_size - 1) {
152 output_buf[y * output->
w + x] = lid;
153 labels[lid].
id = lid;
156 labels[lid].
x_min = x;
157 labels[lid].
y_min = y;
158 labels[lid].
x_sum = x;
159 labels[lid].
y_sum = y;
164 if (labels_cnt >= labels_size - 1) {
165 printf(
"Break did not work: we have %d labels\n", labels_cnt);
169 for (i = 0; i < labels_cnt; i++) {
170 if (labels[i].
id != i) {
178 if (labels[i].x_min < labels[new_id].x_min) { labels[new_id].
x_min = labels[i].
x_min; }
179 if (labels[i].y_min < labels[new_id].y_min) { labels[new_id].
y_min = labels[i].
y_min; }
183 *labels_count = labels_cnt;
186 for (y = 0; y < input->
h; y++) {
187 for (x = 0; x < input->
w / 2; x++) {
188 uint16_t lid = output_buf[y * output->
w + x];
189 if (lid < labels_cnt) {
190 output_buf[y * output->
w + x] = labels[lid].
id;
void image_labeling(struct image_t *input, struct image_t *output, struct image_filter_t *filters, uint8_t filters_cnt, struct image_label_t *labels, uint16_t *labels_count)
Parse UYVY images and make a list of blobs of connected pixels.
uint16_t x_min
Top left corner.
uint32_t pixel_cnt
Number of pixels in the blob.
uint8_t filter
Which filter triggered this blob.
uint32_t x_sum
Sum of all x coordinates (used to find center of gravity)
if(GpsFixValid() &&e_identification_started)
void * buf
Image buffer (depending on the image_type)
static struct FirstOrderLowPass filters[SYS_ID_CHIRP_NB_AXES]
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup)