User Tools

Site Tools


notes:circle-detector

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
notes:circle-detector [2024/09/23 20:36] – Add path to ocv4 adminnotes:circle-detector [2024/10/21 23:01] (current) – Add updated dots.folk code and cameraToProjector note admin
Line 2: Line 2:
  
 > [[https://gist.github.com/nmichaud/7975c461d91229007ec75d7bad8e0d04|This is an adaptation of this gist]], thanks [[https://x.com/naveenma?lang=en|Naveen Michaud-Agrawal]] > [[https://gist.github.com/nmichaud/7975c461d91229007ec75d7bad8e0d04|This is an adaptation of this gist]], thanks [[https://x.com/naveenma?lang=en|Naveen Michaud-Agrawal]]
 +  * TODO: Replace ''cameraToProjector'' with quad translation implementation from ''virtual-programs/mask-tags.folk''
   * TODO: affix relative codepaths below   * TODO: affix relative codepaths below
   * Copy the C++ code paths below onto your Folk machine (make sure your directory names match the paths below)   * Copy the C++ code paths below onto your Folk machine (make sure your directory names match the paths below)
Line 178: Line 179:
  
 # Dot detector using OpenCV # Dot detector using OpenCV
 + 
 set makeDotDetector {{} { set makeDotDetector {{} {
     set detector DotDetector     set detector DotDetector
     namespace eval $detector {     namespace eval $detector {
 + 
         set cc [c create]         set cc [c create]
- +  
-        $cc cflags -I$::env(HOME)/folk/vendor/opencv+        $cc cflags -I$::env(HOME)/opencv
         $cc include <stdio.h>         $cc include <stdio.h>
         $cc include <stdlib.h>         $cc include <stdlib.h>
         $cc include <assert.h>         $cc include <assert.h>
         $cc include "$::env(HOME)/ocv4/OpenCVWrapper.h"         $cc include "$::env(HOME)/ocv4/OpenCVWrapper.h"
 + 
         ::defineImageType $cc         ::defineImageType $cc
         $cc import ::Heap::cc folkHeapAlloc as folkHeapAlloc         $cc import ::Heap::cc folkHeapAlloc as folkHeapAlloc
         $cc import ::Heap::cc folkHeapFree as folkHeapFree         $cc import ::Heap::cc folkHeapFree as folkHeapFree
 + 
         $cc proc detect {image_t gray} Tcl_Obj* {         $cc proc detect {image_t gray} Tcl_Obj* {
             assert(gray.components == 1);             assert(gray.components == 1);
             cv_image_t im = (cv_image_t) { .width = gray.width, .height = gray.height, .components = gray.components, .bytesPerRow = gray.bytesPerRow, .data = gray.data };             cv_image_t im = (cv_image_t) { .width = gray.width, .height = gray.height, .components = gray.components, .bytesPerRow = gray.bytesPerRow, .data = gray.data };
 + 
             int max_count = 100;             int max_count = 100;
             cv_keypoint_t* detections = (cv_keypoint_t*)malloc(sizeof(cv_keypoint_t)*max_count);             cv_keypoint_t* detections = (cv_keypoint_t*)malloc(sizeof(cv_keypoint_t)*max_count);
 + 
             int detectionCount = cvSimpleBlobDetector(im, detections, max_count, true);             int detectionCount = cvSimpleBlobDetector(im, detections, max_count, true);
 + 
             Tcl_Obj* detectionObjs[detectionCount];             Tcl_Obj* detectionObjs[detectionCount];
             for (int i = 0; i < detectionCount; i++) {             for (int i = 0; i < detectionCount; i++) {
                 cv_keypoint_t* det = &detections[i];                 cv_keypoint_t* det = &detections[i];
 + 
                 detectionObjs[i] = Tcl_ObjPrintf("center {%f %f} radius %f",                 detectionObjs[i] = Tcl_ObjPrintf("center {%f %f} radius %f",
                                                  det->x, det->y, det->radius);                                                  det->x, det->y, det->radius);
Line 215: Line 216:
             return result;             return result;
         }         }
- +  
-        c loadlib $::env(HOME)/folk/vendor/opencv/libopencvwrapper.so+        c loadlib $::env(HOME)/ocv4/libopencvwrapper.so
         $cc compile         $cc compile
 + 
         namespace export *         namespace export *
         namespace ensemble create         namespace ensemble create
 + 
     }     }
 + 
     return $detector     return $detector
 }} }}
Line 229: Line 230:
 # Plain detector. Runs on entire camera frame. # Plain detector. Runs on entire camera frame.
 set detectorProcess [Start process { set detectorProcess [Start process {
 + 
   set detector [apply $makeDotDetector]   set detector [apply $makeDotDetector]
 + 
   Wish $::thisProcess receives statements like \   Wish $::thisProcess receives statements like \
-      [list /someone/ claims the camera frame is /grayFrame/ at /timestamp/]+      [list /someone/ claims camera /cam/ has frame /grayFrame/ at timestamp /timestamp/]
   Wish $::thisProcess shares statements like \   Wish $::thisProcess shares statements like \
       [list /someone/ claims /process/ detects dots /dots/ at /timestamp/ in time /dotTime/]       [list /someone/ claims /process/ detects dots /dots/ at /timestamp/ in time /dotTime/]
- +  
-  When the camera frame is /grayFrame/ at /timestamp/ {+  When camera /cam/ has frame /grayFrame/ at timestamp /timestamp/  {
       set dotTime [time {       set dotTime [time {
           set dots [$detector detect $grayFrame]           set dots [$detector detect $grayFrame]
Line 244: Line 245:
   }   }
 }] }]
- +  
 + 
 When /someone/ detects dots /dots/ at /timestamp/ in time /dotTime/ & \ When /someone/ detects dots /dots/ at /timestamp/ in time /dotTime/ & \
    /obj/ has region /region/ {    /obj/ has region /region/ {
 + 
   set dots [lmap dot $dots { dict create center [lmap d [::cameraToProjector [dict get $dot center]] {round $d }] }]   set dots [lmap dot $dots { dict create center [lmap d [::cameraToProjector [dict get $dot center]] {round $d }] }]
 + 
   set contained [list ]   set contained [list ]
   foreach dot $dots {   foreach dot $dots {
notes/circle-detector.txt · Last modified: by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki