From b7491c42f2d802b0a184e173ed21571f79fca0eb Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Mon, 29 Apr 2024 16:44:12 -0400 Subject: Changes from osnr/checkerboard-calibration for projecting tags Support global functions in shaders; support uvec4 argtype in shaders; carve out tag 48600 and up for self-calibration; expose ::tagImageForId and rename ::tagPsForId. --- virtual-programs/apriltags.folk | 3 +++ virtual-programs/print.folk | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/apriltags.folk b/virtual-programs/apriltags.folk index 49b83e5a..499d8ed3 100644 --- a/virtual-programs/apriltags.folk +++ b/virtual-programs/apriltags.folk @@ -108,6 +108,9 @@ When the collected matches for [list /someone/ detects tags /tags/ at /timestamp set timestamp [dict get $match timestamp] foreach tag [dict get $match tags] { set id [dict get $tag id] + # Setting aside this tag space (48600 to 48713) for calibration. + if {$id >= 48600} { continue } + dict set tag timestamp $timestamp if {[dict exists $::tagsCache $id] && diff --git a/virtual-programs/print.folk b/virtual-programs/print.folk index 6197bdd1..082f48cb 100644 --- a/virtual-programs/print.folk +++ b/virtual-programs/print.folk @@ -3,6 +3,7 @@ source "pi/cUtils.tcl" set cc [c create] $cc cflags -I$::env(HOME)/apriltag -Wall -Werror $::env(HOME)/apriltag/libapriltag.a c loadlib $::env(HOME)/apriltag/libapriltag.so +::defineImageType $cc $cc code { #include @@ -11,7 +12,21 @@ $cc code { #define emit(...) i += sprintf(&ret[i], __VA_ARGS__) } -$cc proc ::tagImageForId {int id} char* { + +# HACK (osnr): This is used when someone wants to draw an AprilTag +# (often for calibration/cnc preview purposes); I put it here because +# we already have a whole AprilTag family and C compiler object setup +# here. The returned image_t's data needs to be freed by the caller. +$cc proc ::tagImageForId {int id} image_t { + if (tf == NULL) tf = tagStandard52h13_create(); + + image_u8_t* image = apriltag_to_image(tf, id); + image_t ret = (image_t) { .width = image->width, .height = image->height, .components = 1, .bytesPerRow = image->stride, .data = image->buf }; + free(image); // doesn't free data + return ret; +} + +$cc proc ::tagPsForId {int id} char* { if (tf == NULL) tf = tagStandard52h13_create(); image_u8_t* image = apriltag_to_image(tf, id); @@ -51,7 +66,7 @@ proc ::programToPs {id text {format "letter"} {side "front"}} { set fontsize 8; set lineheight [expr $fontsize*1.5] set margin 36 if {$side eq "front"} { - set image [::tagImageForId $id] + set tagPs [::tagPsForId $id] return [subst { %!PS << /PageSize \[$PageWidth $PageHeight\] >> setpagedevice @@ -61,7 +76,7 @@ proc ::programToPs {id text {format "letter"} {side "front"}} { gsave [expr $PageHeight-$tagheight-$margin] [expr -$margin-$tagwidth] translate $tagwidth $tagheight scale - $image + $tagPs grestore /Helvetica-Narrow findfont -- cgit v1.2.3