guides:opencv
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| guides:opencv [2024/01/30 02:11] – created discord | guides:opencv [2024/02/02 04:22] (current) – discord | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Instructions for integrating OpenCV with Folk. | + | //Original Author: Jacob Haip. |
| + | Contributions welcome!// | ||
| + | |||
| + | Instructions for integrating OpenCV with Folk. This guide involves a manual compilation set outside of folk, but the creation of the wrapper files and the compilation (via an TCL " | ||
| 1. Install OpenCV | 1. Install OpenCV | ||
| Line 5: | Line 8: | ||
| sudo apt-get install -y libopencv-dev | sudo apt-get install -y libopencv-dev | ||
| - | 2. Create a C wrapper for the OpenCV functions you want to use | + | 2. Create a C wrapper for the OpenCV functions you want to use. I saved these files in a new ~/ |
| OpenCVWrapper.h | OpenCVWrapper.h | ||
| Line 96: | Line 99: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | 3. Compile the wrapper | ||
| + | |||
| + | g++ -fPIC -shared OpenCVWrapper.cpp -o libopencvwrapper.so `pkg-config --cflags --libs opencv4` | ||
| + | |||
| + | 4. Use the compiled libopencvwrapper.so and .h file in your folk C code | ||
| + | |||
| + | <code tcl> | ||
| + | set cc [c create] | ||
| + | defineImageType $cc | ||
| + | $cc cflags -I$:: | ||
| + | |||
| + | $cc include < | ||
| + | $cc include " | ||
| + | |||
| + | if {[namespace exists ::Heap]} { | ||
| + | $cc import ::Heap::cc folkHeapAlloc as folkHeapAlloc | ||
| + | $cc import ::Heap::cc folkHeapFree as folkHeapFree | ||
| + | } else { | ||
| + | $cc code { #define folkHeapAlloc malloc } | ||
| + | $cc code { #define folkHeapFree free } | ||
| + | } | ||
| + | |||
| + | $cc proc opencvAdaptiveThreshold {image_t img} image_t { | ||
| + | cv_image_t im2 = (cv_image_t) { .width = img.width, .height = img.height, .components = img.components, | ||
| + | cv_image_t r = myAdaptiveThreshold(im2); | ||
| + | image_t ret = (image_t) { .width = r.width, .height = r.height, .components = r.components, | ||
| + | memcpy(ret.data, | ||
| + | return ret; | ||
| + | } | ||
| + | |||
| + | c loadlib $:: | ||
| + | $cc compile | ||
| + | |||
| + | When $this has region /r/ { | ||
| + | Claim $this' has region [region move $r down 110%] | ||
| + | } | ||
| + | |||
| + | set :: | ||
| + | When $this' has camera slice /slice/ & $this has region /r/ { | ||
| + | set grayImg [opencvAdaptiveThreshold $slice] | ||
| + | set center [region centroid $r] | ||
| + | Wish to draw an image with center $center image $grayImg radians 0 scale 2 | ||
| + | |||
| + | lappend :: | ||
| + | if {[llength $:: | ||
| + | set :: | ||
| + | image freeImage $oldestFrame | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | {{: | ||
guides/opencv.1706580716.txt.gz · Last modified: by discord
