mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add check for array length
This commit is contained in:
parent
3a18b8f4b6
commit
0fd2047fad
@ -16,13 +16,18 @@ array_t *imlib_count_blobs(struct image *image)
|
|||||||
for (int x=0; x<image->w; x++) {
|
for (int x=0; x<image->w; x++) {
|
||||||
int i=y*image->w+x;
|
int i=y*image->w+x;
|
||||||
if (pixels[i]) {
|
if (pixels[i]) {
|
||||||
/* new blob */
|
/* new blob */
|
||||||
rectangle_t *blob = rectangle_alloc(image->w, image->h, 0, 0);
|
rectangle_t *blob = rectangle_alloc(image->w, image->h, 0, 0);
|
||||||
array_push_back(blobs, blob);
|
array_push_back(blobs, blob);
|
||||||
|
|
||||||
/* flood fill */
|
/* flood fill */
|
||||||
point_t *p=point_alloc(x, y);
|
point_t *p=point_alloc(x, y);
|
||||||
while(p != NULL) {
|
while(p != NULL) {
|
||||||
|
if (array_length(points) > 500) {
|
||||||
|
xfree(p);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
/* add point to blob */
|
/* add point to blob */
|
||||||
if (p->x < blob->x) {
|
if (p->x < blob->x) {
|
||||||
blob->x = p->x;
|
blob->x = p->x;
|
||||||
@ -71,6 +76,7 @@ array_t *imlib_count_blobs(struct image *image)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
for (int i=0; i<array_length(blobs); i++) {
|
for (int i=0; i<array_length(blobs); i++) {
|
||||||
rectangle_t *blob = array_at(blobs, i);
|
rectangle_t *blob = array_at(blobs, i);
|
||||||
// if (blob->w < 10) { /* blob too small */
|
// if (blob->w < 10) { /* blob too small */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user