{"id":50623389,"url":"https://github.com/sivakov512/libgauge","last_synced_at":"2026-06-06T14:30:29.589Z","repository":{"id":346691505,"uuid":"1180291256","full_name":"sivakov512/libgauge","owner":"sivakov512","description":"C library for reading analog gauge values from video frames. Designed for constrained environments.","archived":false,"fork":false,"pushed_at":"2026-03-25T02:57:27.000Z","size":1277,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-26T07:54:19.474Z","etag":null,"topics":["analog-gauge","bare-metal","c","c-library","camera","computer-vision","cv","embedded","image-processing","no-dependencies"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sivakov512.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"sivakov512","ko_fi":"sivakov512"}},"created_at":"2026-03-12T22:31:56.000Z","updated_at":"2026-03-25T02:57:30.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sivakov512/libgauge","commit_stats":null,"previous_names":["sivakov512/libgauge"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sivakov512/libgauge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivakov512%2Flibgauge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivakov512%2Flibgauge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivakov512%2Flibgauge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivakov512%2Flibgauge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sivakov512","download_url":"https://codeload.github.com/sivakov512/libgauge/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sivakov512%2Flibgauge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33986901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-06T02:00:07.033Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analog-gauge","bare-metal","c","c-library","camera","computer-vision","cv","embedded","image-processing","no-dependencies"],"created_at":"2026-06-06T14:30:28.956Z","updated_at":"2026-06-06T14:30:29.580Z","avatar_url":"https://github.com/sivakov512.png","language":"C","funding_links":["https://github.com/sponsors/sivakov512","https://ko-fi.com/sivakov512"],"categories":[],"sub_categories":[],"readme":"# libgauge\n\n[![Checks](https://github.com/sivakov512/libgauge/actions/workflows/checks.yml/badge.svg)](https://github.com/sivakov512/libgauge/actions/workflows/checks.yml)\n[![Formatting](https://github.com/sivakov512/libgauge/actions/workflows/formatting.yml/badge.svg)](https://github.com/sivakov512/libgauge/actions/workflows/formatting.yml)\n\nC library for reading analog gauge values from video frames. Designed for constrained environments — no OpenCV, no heavy dependencies. Works on embedded systems with a camera.\n\nPython reference implementation used for algorithm prototyping: [sivakov512/libgauge-reference](https://github.com/sivakov512/libgauge-reference).\n\n## Requirements\n\n- CMake 3.16+\n- C99 compiler\n- `libm` (standard math library)\n\n## Integration\n\n\u003c!--x-release-please-start-version--\u003e\n```cmake\ninclude(FetchContent)\n\nFetchContent_Declare(\n    gauge\n    GIT_REPOSITORY https://github.com/sivakov512/libgauge.git\n    GIT_TAG        v1.0.0\n)\nFetchContent_MakeAvailable(gauge)\n\ntarget_link_libraries(your_target PRIVATE gauge)\n```\n\u003c!--x-release-please-end--\u003e\n\nInclude the headers you need:\n\n```c\n#include \"gauge.h\"       // calibration and measurement\n#include \"gauge/cv.h\"    // computer vision primitives\n#include \"gauge/utils.h\" // angle utilities\n```\n\n## Usage\n\n### 1. Prepare frames\n\nFrames are grayscale, row-major. You allocate the buffer:\n\n```c\nuint8_t buf[WIDTH * HEIGHT];\ngauge_frame_t frame = {\n    .buf    = buf,\n    .width  = WIDTH,\n    .height = HEIGHT,\n};\n```\n\nUse `GAUGE_SCRATCH_SIZE(width, height)` to declare the scratch buffer required by\ncalibration and blob extraction:\n\n```c\nsize_t scratch[GAUGE_SCRATCH_SIZE(WIDTH, HEIGHT)];\n```\n\n### 2. Build background\n\nPass each frame from a static scene (no arrow movement) to build a per-pixel maximum\nbackground. Start with `bg.buf` zeroed:\n\n```c\nuint8_t bg_buf[WIDTH * HEIGHT] = {0};\ngauge_frame_t bg = {.buf = bg_buf, .width = WIDTH, .height = HEIGHT};\n\nfor (size_t i = 0; i \u003c frame_count; i++) {\n    gauge_err_t err = gauge_update_background(\u0026frames[i], \u0026bg);\n    if (err != GAUGE_OK) { /* handle error */ }\n}\n```\n\n### 3. Calibrate geometry\n\nProvide the first frame (arrow at minimum position) and the last frame (arrow at\nmaximum position), along with the background:\n\n```c\ngauge_calibration_data_t ca_data;\ngauge_err_t err = gauge_calibrate_by_axis_intersection(\n    \u0026first, \u0026last, \u0026bg, GAUGE_BINARIZATION_THRESHOLD,\n    scratch, GAUGE_SCRATCH_SIZE(WIDTH, HEIGHT), \u0026ca_data);\nif (err != GAUGE_OK) { /* handle error */ }\n```\n\n`ca_data.spin` is `GAUGE_SPIN_UNKNOWN` at this point.\n\n### 4. Determine spin direction\n\nPass a frame where the arrow has moved noticeably from its start position:\n\n```c\ngauge_err_t err = gauge_calibrate_spin(\n    \u0026frame, \u0026bg, GAUGE_BINARIZATION_THRESHOLD,\n    scratch, GAUGE_SCRATCH_SIZE(WIDTH, HEIGHT), \u0026ca_data);\nif (err == GAUGE_ERR_SPIN_UNDETERMINED) { /* arrow hasn't moved enough, try next frame */ }\n```\n\nRepeat with subsequent frames until `GAUGE_OK` is returned.\n\n### 5. Measure\n\nFor each new frame, call:\n\n```c\nfloat angle;\ngauge_err_t err = gauge_scan_radial(\u0026frame, \u0026ca_data, GAUGE_RADIAL_SCAN_STEP, \u0026angle);\nif (err != GAUGE_OK) { /* handle error */ }\n```\n\nReturns the arrow angle in radians, normalized to `[-π, π]`. Map it to a scale value\nusing your known angle-to-value calibration.\n\n---\n\n## Calibration methods\n\n### `gauge_update_background`\n\nAccepts frames one at a time and updates `bg` in-place via per-pixel maximization.\nCall once per frame with `bg-\u003ebuf` zeroed on the first call.\n\n### `gauge_calibrate_by_axis_intersection`\n\n**Algorithm:**\n\n1. Subtract background from first and last frames — only the arrow remains.\n2. Binarize each result using the provided threshold.\n3. Extract the largest blob from each binarized frame.\n4. Fit a line through each blob using principal component analysis.\n5. Intersect the two lines to find the rotation pivot.\n6. Compute the arrow length as the maximum pixel distance from pivot to blob.\n\n`ca_data_out-\u003espin` is set to `GAUGE_SPIN_UNKNOWN`; call `gauge_calibrate_spin`\nafterward to determine direction.\n\n### `gauge_calibrate_spin`\n\n**Algorithm:**\n\n1. Subtract background, binarize, extract the arrow blob.\n2. Compute the arrow angle relative to `ca_data-\u003epivot`.\n3. If the angular difference from `ca_data-\u003eangle_start_rad` exceeds\n   `GAUGE_CALIBRATE_SPIN_MIN_ANGLE_RAD` (~10°), write the spin direction and\n   return `GAUGE_OK`. Otherwise return `GAUGE_ERR_SPIN_UNDETERMINED`.\n\n---\n\n## Measurement methods\n\n### `gauge_scan_radial`\n\n**Algorithm:**\n\nScans radially from `angle_start_rad` to `angle_end_rad` in steps of\n`radial_scan_step`. At each angle, walks from the pivot along the radial direction\nfor `arrow_len` pixels, accumulating `255 - pixel_value` as a score. The angle with\nthe highest score is written to `angle_out`, normalized to `[-π, π]`.\n\n**Default step:** `GAUGE_RADIAL_SCAN_STEP` (~0.5°). Smaller steps give higher angular\nresolution at the cost of more computation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsivakov512%2Flibgauge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsivakov512%2Flibgauge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsivakov512%2Flibgauge/lists"}