Skip to content

Commit d185f23

Browse files
committed
Cache unionfind structure across detect calls and lazy-initialize size array
1 parent 40c8a10 commit d185f23

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

apriltag.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,9 @@ void apriltag_detector_destroy(apriltag_detector_t *td)
411411
apriltag_detector_clear_families(td);
412412

413413
zarray_destroy(td->tag_families);
414-
if (td->cached_uf)
414+
if (td->cached_uf) {
415415
unionfind_destroy(td->cached_uf);
416+
}
416417
free(td);
417418
}
418419

apriltag_quad_thresh.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ struct cluster_task
102102
int w;
103103
int s;
104104
int nclustermap;
105-
int min_cluster_pixels;
106105
unionfind_t* uf;
107106
image_u8_t* im;
108107
zarray_t* clusters;
@@ -1568,7 +1567,7 @@ unionfind_t* connected_components(apriltag_detector_t *td, image_u8_t* threshim,
15681567
return uf;
15691568
}
15701569

1571-
zarray_t* do_gradient_clusters(image_u8_t* threshim, int ts, int y0, int y1, int w, int nclustermap, int min_cluster_pixels, unionfind_t* uf, zarray_t* clusters) {
1570+
zarray_t* do_gradient_clusters(image_u8_t* threshim, int ts, int y0, int y1, int w, int nclustermap, unionfind_t* uf, zarray_t* clusters) {
15721571
struct uint64_zarray_entry **clustermap = calloc(nclustermap, sizeof(struct uint64_zarray_entry*));
15731572

15741573
int mem_chunk_size = 2048;
@@ -1589,7 +1588,7 @@ zarray_t* do_gradient_clusters(image_u8_t* threshim, int ts, int y0, int y1, int
15891588

15901589
// XXX don't query this until we know we need it?
15911590
uint64_t rep0 = unionfind_get_representative(uf, y*w + x);
1592-
if ((int)unionfind_get_set_size(uf, rep0) < min_cluster_pixels) {
1591+
if (unionfind_get_set_size(uf, rep0) < 25) {
15931592
connected_last = false;
15941593
continue;
15951594
}
@@ -1621,7 +1620,7 @@ zarray_t* do_gradient_clusters(image_u8_t* threshim, int ts, int y0, int y1, int
16211620
\
16221621
if (v0 + v1 == 255) { \
16231622
uint64_t rep1 = unionfind_get_representative(uf, (y + dy)*w + x + dx); \
1624-
if ((int)unionfind_get_set_size(uf, rep1) >= min_cluster_pixels) { \
1623+
if (unionfind_get_set_size(uf, rep1) > 24) { \
16251624
uint64_t clusterid; \
16261625
if (rep0 < rep1) \
16271626
clusterid = (rep1 << 32) + rep0; \
@@ -1716,7 +1715,7 @@ static void do_cluster_task(void *p)
17161715
{
17171716
struct cluster_task *task = (struct cluster_task*) p;
17181717

1719-
do_gradient_clusters(task->im, task->s, task->y0, task->y1, task->w, task->nclustermap, task->min_cluster_pixels, task->uf, task->clusters);
1718+
do_gradient_clusters(task->im, task->s, task->y0, task->y1, task->w, task->nclustermap, task->uf, task->clusters);
17201719
}
17211720

17221721
zarray_t* merge_clusters(zarray_t* c1, zarray_t* c2) {
@@ -1779,7 +1778,6 @@ zarray_t* gradient_clusters(apriltag_detector_t *td, image_u8_t* threshim, int w
17791778
tasks[ntasks].uf = uf;
17801779
tasks[ntasks].im = threshim;
17811780
tasks[ntasks].nclustermap = nclustermap/(sz / chunksize + 1);
1782-
tasks[ntasks].min_cluster_pixels = td->qtp.min_cluster_pixels;
17831781
tasks[ntasks].clusters = zarray_create(sizeof(struct cluster_hash*));
17841782

17851783
workerpool_add_task(td->wp, do_cluster_task, &tasks[ntasks]);

common/workerpool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void *worker_thread(void *p)
8181
zarray_get_volatile(wp->tasks, wp->taskspos, &task);
8282
wp->taskspos++;
8383
pthread_mutex_unlock(&wp->mutex);
84+
sched_yield();
8485

8586
// we've been asked to exit.
8687
if (task->f == NULL)

0 commit comments

Comments
 (0)