Skip to content

Replace OpenCV imgcodecs with vendored stb-based lar_io - #69

Merged
kobejean merged 2 commits into
mainfrom
feat/lar-io-image-codec
Jul 4, 2026
Merged

Replace OpenCV imgcodecs with vendored stb-based lar_io#69
kobejean merged 2 commits into
mainfrom
feat/lar-io-image-codec

Conversation

@kobejean

@kobejean kobejean commented Jul 4, 2026

Copy link
Copy Markdown
Owner

What & why

Removes the OpenCV imgcodecs dependency (and the libjpeg/zlib it dragged in) by introducing a small lar_io leaf library that owns all image I/O. This is step 1 of gradually reducing our OpenCV surface, and it makes tracking-only binaries codec-free.

Changes

  • New lar_io target — vendored stb_image/stb_image_write (pinned) for JPEG + a small OpenCV-compatible PFM codec in lar/io/image_io.{h,cpp}. It's the only module that links an image codec.
  • All cv::imread/cv::imwrite call sites swapped (src, apps, tests). Readers return an empty cv::Mat on failure to match cv::imread's contract.
  • Frame moved into lar_core, and the lar_tracking → lar_mapping link edge removed — so tracking's link closure is {core, tracking, opencv_core/geometry/imgproc/features/flann, g2o, eigen, json}, i.e. codec-free by construction.
  • imgcodecs dropped from find_package, the SuperBuild BUILD_LIST (with JPEG/zlib off), and the xcframework build (--without imgcodecs).
  • Dead-strip flags (-ffunction-sections -fdata-sections + --gc-sections/-dead_strip) so unreferenced module code is dropped from final binaries.

Verification

  • Codec byte-compatibility proven against system OpenCV as oracle: lar-written PFM reads identically in OpenCV, OpenCV-written PFM (existing fixtures) reads identically in lar, JPEG round-trips, and the BGR→RGB swap direction is correct.
  • Tracking codec-free verified statically from the link graph.
  • ⚠️ Full make tests should be run in an OpenCV-5 environment (the machine used here had a stale OpenCV-4 build); mapper_test round-trips the .jpeg/.pfm fixtures and is the natural end-to-end gate.

🤖 Generated with Claude Code

Add a lar_io leaf library that handles all image I/O (JPEG via vendored
stb, plus a small OpenCV-compatible PFM codec), replacing every
cv::imread/cv::imwrite call site. Only mapping and processing link it, so
tracking-only binaries carry no image-codec code.

- Add thirdparty/stb (stb_image / stb_image_write, pinned) and
  lar/io/image_io.{h,cpp}. PFM byte layout verified round-trip compatible
  with OpenCV's imread/imwrite; readers return empty Mat on failure to
  match cv::imread's contract.
- Move Frame into lar_core and drop the lar_tracking -> lar_mapping link
  edge, so tracking's link closure is codec-free by construction.
- Drop imgcodecs (and libjpeg/zlib) from find_package, the SuperBuild
  BUILD_LIST, and the xcframework build (--without imgcodecs).
- Add -ffunction-sections/-fdata-sections + linker dead-strip so
  unreferenced module code is dropped from final binaries.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… runtime

sift_impl_metal.mm (compiled into lar_tracking.a) uses the Objective-C
runtime (NSString, @try/@catch), but the Metal block only linked Metal +
MetalPerformanceShaders. Executables such as lar_localize previously got
libobjc incidentally through opencv_imgcodecs' transitive framework deps;
now that image I/O lives in lar_io, that link is gone and lar_localize
failed with undefined _objc_* symbols.

Link Foundation explicitly, and make the Metal/MPS/Foundation frameworks
PUBLIC since the .mm lives in lar_tracking.a and thus every consumer of
lar_tracking needs them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kobejean
kobejean merged commit b701fbf into main Jul 4, 2026
2 checks passed
@kobejean
kobejean deleted the feat/lar-io-image-codec branch July 4, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant