Skip to content

Conversation

@ctacke
Copy link

@ctacke ctacke commented Jan 25, 2026

This source chance allows you to build OpenCvSharpExtern to match a stripped-down build of OpenCV. This allows for an app to use OpenCV in an embedded app without having to install the very large opencv-dev package. For example, the stripped-down no-contrib build supporting USB camera streaming and frame capture is only about 16MB for all of the OpenCV bits.

This PR included a readme that explains things a bit, as well as a couple reference scripts to build full and no-contrib binary sets. I have binary release sets for linux-arm64 in my fork.

Copilot AI review requested due to automatic review settings January 25, 2026 18:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configurable “minimal / no-contrib” build path for OpenCvSharpExtern so it can link against stripped-down OpenCV builds (notably for linux-arm64 / Raspberry Pi), plus documentation and helper scripts to build/deploy those binaries.

Changes:

  • Introduces CMake feature flags (NO_CONTRIB, NO_*) to conditionally compile subsets of OpenCvSharpExtern.
  • Wraps many module/contrib bindings in preprocessor guards so missing OpenCV modules don’t break linkage.
  • Adds linux-arm64 build scripts and an embedded build guide, linked from the main README.

Reviewed changes

Copilot reviewed 67 out of 67 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
tool/build-opencvsharp-minimal-arm64.sh New helper script to build a minimal OpenCV + matching OpenCvSharpExtern for linux-arm64 and stage .so outputs
tool/build-opencvsharp-arm64.sh New helper script to build OpenCV + contrib + OpenCvSharpExtern for linux-arm64 and stage .so outputs
src/CMakeLists.txt Adds CMake options for disabling module bindings and attempts to translate them into compile definitions
embedded-builds.md New embedded/ARM build documentation and usage instructions for the scripts/manual builds
README.md Links to the new embedded build documentation
src/OpenCvSharpExtern/include_opencv.h Makes OpenCV header inclusion conditional on NO_* feature defines
src/OpenCvSharpExtern/std_vector.h Wraps ML/stitching-related vector bindings to avoid referencing disabled modules
src/OpenCvSharpExtern/aruco.h Wraps aruco (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/bgsegm.h Wraps bgsegm (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/img_hash.h Wraps img_hash (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/line_descriptor.h Wraps line_descriptor (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/optflow.h Wraps optflow (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/optflow_motempl.h Wraps motempl (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/quality.h Wraps quality (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/tracking.h Wraps tracking (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/wechat_qrcode.h Wraps wechat_qrcode (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/xfeatures2d.h Wraps xfeatures2d (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/ximgproc.h Wraps ximgproc (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/ximgproc_EdgeBoxes.h Wraps ximgproc EdgeBoxes bindings behind NO_CONTRIB
src/OpenCvSharpExtern/ximgproc_EdgeFilter.h Wraps ximgproc EdgeFilter bindings behind NO_CONTRIB
src/OpenCvSharpExtern/ximgproc_FastLineDetector.h Wraps ximgproc FastLineDetector bindings behind NO_CONTRIB
src/OpenCvSharpExtern/ximgproc_RidgeDetectionFilter.h Wraps ximgproc RidgeDetectionFilter bindings behind NO_CONTRIB
src/OpenCvSharpExtern/ximgproc_Segmentation.h Wraps ximgproc Segmentation bindings behind NO_CONTRIB
src/OpenCvSharpExtern/ximgproc_StructuredEdgeDetection.h Wraps ximgproc StructuredEdgeDetection bindings behind NO_CONTRIB
src/OpenCvSharpExtern/ximgproc_SuperPixel.h Wraps ximgproc SuperPixel bindings behind NO_CONTRIB
src/OpenCvSharpExtern/xphoto.h Wraps xphoto (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/features2d.h Wraps features2d bindings behind NO_FEATURES2D
src/OpenCvSharpExtern/features2d_BOW.h Wraps features2d BOW bindings behind NO_FEATURES2D
src/OpenCvSharpExtern/features2d_DescriptorMatcher.h Wraps features2d DescriptorMatcher bindings behind NO_FEATURES2D
src/OpenCvSharpExtern/features2d_Feature2D.h Wraps features2d Feature2D bindings behind NO_FEATURES2D
src/OpenCvSharpExtern/flann.h Wraps flann bindings behind NO_FLANN
src/OpenCvSharpExtern/flann_IndexParams.h Wraps flann IndexParams bindings behind NO_FLANN
src/OpenCvSharpExtern/dnn.h Wraps dnn bindings behind NO_DNN
src/OpenCvSharpExtern/dnn_Net.h Wraps dnn Net bindings behind NO_DNN
src/OpenCvSharpExtern/ml.h Wraps ml bindings behind NO_ML
src/OpenCvSharpExtern/ml_ANN_MLP.h Wraps ANN_MLP bindings behind NO_ML
src/OpenCvSharpExtern/ml_Boost.h Wraps Boost bindings behind NO_ML
src/OpenCvSharpExtern/ml_DTrees.h Wraps DTrees bindings behind NO_ML
src/OpenCvSharpExtern/ml_EM.h Wraps EM bindings behind NO_ML
src/OpenCvSharpExtern/ml_KNearest.h Wraps KNearest bindings behind NO_ML
src/OpenCvSharpExtern/ml_LogisticRegression.h Wraps LogisticRegression bindings behind NO_ML
src/OpenCvSharpExtern/ml_NormalBayesClassifier.h Wraps NormalBayesClassifier bindings behind NO_ML
src/OpenCvSharpExtern/ml_RTrees.h Wraps RTrees bindings behind NO_ML
src/OpenCvSharpExtern/ml_SVM.h Wraps SVM bindings behind NO_ML
src/OpenCvSharpExtern/ml_StatModel.h Wraps StatModel bindings behind NO_ML
src/OpenCvSharpExtern/objdetect.h Wraps objdetect bindings behind NO_OBJDETECT
src/OpenCvSharpExtern/objdetect_HOGDescriptor.h Wraps HOGDescriptor bindings behind NO_OBJDETECT
src/OpenCvSharpExtern/objdetect_QRCodeDetector.h Wraps QRCodeDetector bindings behind NO_OBJDETECT
src/OpenCvSharpExtern/photo.h Wraps photo bindings behind NO_PHOTO
src/OpenCvSharpExtern/photo_HDR.h Wraps HDR helpers behind NO_PHOTO
src/OpenCvSharpExtern/photo_Tonemap.h Wraps tonemap helpers behind NO_PHOTO
src/OpenCvSharpExtern/stitching.h Wraps stitching bindings behind NO_STITCHING
src/OpenCvSharpExtern/stitching_detail_Matchers.h Wraps stitching detail matcher bindings behind NO_STITCHING
src/OpenCvSharpExtern/calib3d.h Wraps calib3d bindings behind NO_CALIB3D
src/OpenCvSharpExtern/calib3d_fisheye.h Wraps fisheye helpers behind NO_CALIB3D
src/OpenCvSharpExtern/calib3d_StereoMatcher.h Wraps StereoMatcher helpers behind NO_CALIB3D
src/OpenCvSharpExtern/video.h Wraps video includes behind NO_VIDEO
src/OpenCvSharpExtern/video_tracking.h Wraps video tracking bindings behind NO_VIDEO
src/OpenCvSharpExtern/video_background_segm.h Wraps video background segmentation bindings behind NO_VIDEO
src/OpenCvSharpExtern/text.h Wraps text (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/text_TextDetector.h Wraps TextDetector (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/superres.h Wraps superres (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/shape_ShapeDistanceExtractor.h Wraps shape (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/dnn_superres.h Wraps dnn_superres (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/face_Facemark.h Wraps face facemark (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/face_FaceRecognizer.h Wraps face recognizer (contrib) bindings behind NO_CONTRIB
src/OpenCvSharpExtern/barcode.h Wraps barcode bindings behind NO_BARCODE
Comments suppressed due to low confidence (1)

src/OpenCvSharpExtern/superres.h:354

  • The #endif comment doesn’t match the opening condition (#ifndef _WINRT_DLL). This is minor, but it makes the preprocessor nesting harder to follow; consider changing it to reflect the actual condition being closed (e.g., “!_WINRT_DLL”).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +7
ROOT_DIR=$(pwd)
INSTALL_PREFIX="$ROOT_DIR/opencv-install"
RUNTIME_DIR="$ROOT_DIR/runtimes/linux-arm64/native"

Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script assumes it’s run from a directory that contains opencv/, opencv_contrib/, and opencvsharp/ as children because it uses ROOT_DIR=$(pwd). To make it harder to run from the wrong working directory, consider deriving paths from the script location and/or validating that the expected directories exist before continuing.

Copilot uses AI. Check for mistakes.

Using a Raspberry Pi with a 64-bit build of Debian Trixie (Lite is fine)

If you want a build of OpenCV that minimizes the on-disk footprint, you can turn off features (i.e. omit them from the build) for a custom OpenCV build. If you do this, you must also build a custom OpenCvExtern library that matches your configuration.
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text refers to building a custom OpenCvExtern library, but the native wrapper in this repo is named OpenCvSharpExtern. This is likely to confuse readers following the instructions.

Suggested change
If you want a build of OpenCV that minimizes the on-disk footprint, you can turn off features (i.e. omit them from the build) for a custom OpenCV build. If you do this, you must also build a custom OpenCvExtern library that matches your configuration.
If you want a build of OpenCV that minimizes the on-disk footprint, you can turn off features (i.e. omit them from the build) for a custom OpenCV build. If you do this, you must also build a custom OpenCvSharpExtern library that matches your configuration.

Copilot uses AI. Check for mistakes.

You can build a subset, but it takes some work. The way Linux libraries link, you have to handle all of the dependencies. You can't simply rebuild OpenCV with fewer features and have it work. OpenCvSharpExtern is linked to the endpoints of all of the features in OpenCV, so if some of them are missing, loading `libOpenCvSharpExtern.so` will fail even if you aren't using the missing features. You must rebuild both, and the original OpenCVSharpExtern is not created to make this friendly.

This fork attempts to address that (and maybe it will get merged back in - I'll certainly PR it).
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is written as if it’s documentation in a personal fork (e.g., “This fork attempts to address that…”). If this is being merged upstream, the wording should be updated to refer to this repository/PR rather than a fork, otherwise the instructions become misleading.

Suggested change
This fork attempts to address that (and maybe it will get merged back in - I'll certainly PR it).
This repository attempts to address that by providing better support for minimal, configurable builds.

Copilot uses AI. Check for mistakes.
cd ~
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git # only needed for full build
git clone https://github.com/ctacke/opencvsharp.git
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guide currently instructs users to clone https://github.com/ctacke/opencvsharp.git. If this documentation is intended for the upstream repo, this should point to the canonical repository (e.g., https://github.com/shimat/opencvsharp.git) or use a relative reference, otherwise readers will end up on the wrong codebase.

Suggested change
git clone https://github.com/ctacke/opencvsharp.git
git clone https://github.com/shimat/opencvsharp.git

Copilot uses AI. Check for mistakes.
Comment on lines +178 to +182
First, clone the code. It's important that you clone this fork, not the original, so that the proper defines are in the code.

```bash
cd ~
git clone https://github.com/ctacke/opencvsharp.git
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as earlier in the doc: this section tells readers to clone https://github.com/ctacke/opencvsharp.git. After merging upstream, the instructions should reference this repository (or clearly explain why a fork is required).

Suggested change
First, clone the code. It's important that you clone this fork, not the original, so that the proper defines are in the code.
```bash
cd ~
git clone https://github.com/ctacke/opencvsharp.git
First, clone the OpenCvSharp repository that contains the matching build configuration.
```bash
cd ~
git clone https://github.com/shimat/opencvsharp.git

Copilot uses AI. Check for mistakes.
Comment on lines +274 to +275
#endif // _WINRT_DLL
#endif // NO_CONTRIB
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #endif comment doesn’t match the opening condition (#ifndef _WINRT_DLL). This is minor, but it makes the preprocessor nesting harder to follow; consider changing it to reflect the actual condition being closed (e.g., “!_WINRT_DLL”).

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +57
add_compile_definitions(NO_CONTRIB)
endif()
if(NO_STITCHING)
add_compile_definitions(NO_STITCHING)
endif()
if(NO_CALIB3D)
add_compile_definitions(NO_CALIB3D)
endif()
if(NO_VIDEO)
add_compile_definitions(NO_VIDEO)
endif()
if(NO_FEATURES2D)
add_compile_definitions(NO_FEATURES2D)
endif()
if(NO_FLANN)
add_compile_definitions(NO_FLANN)
endif()
if(NO_DNN)
add_compile_definitions(NO_DNN)
endif()
if(NO_ML)
add_compile_definitions(NO_ML)
endif()
if(NO_OBJDETECT)
add_compile_definitions(NO_OBJDETECT)
endif()
if(NO_PHOTO)
add_compile_definitions(NO_PHOTO)
endif()
if(NO_BARCODE)
add_compile_definitions(NO_BARCODE)
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_compile_definitions() requires newer CMake (>=3.12), but this project declares cmake_minimum_required(VERSION 3.0), so configuring with older CMake will fail. Either bump the minimum required CMake version accordingly, or replace these with a CMake-3.0-compatible approach (e.g., add_definitions(-D...) or target_compile_definitions() on the OpenCvSharpExtern target).

Suggested change
add_compile_definitions(NO_CONTRIB)
endif()
if(NO_STITCHING)
add_compile_definitions(NO_STITCHING)
endif()
if(NO_CALIB3D)
add_compile_definitions(NO_CALIB3D)
endif()
if(NO_VIDEO)
add_compile_definitions(NO_VIDEO)
endif()
if(NO_FEATURES2D)
add_compile_definitions(NO_FEATURES2D)
endif()
if(NO_FLANN)
add_compile_definitions(NO_FLANN)
endif()
if(NO_DNN)
add_compile_definitions(NO_DNN)
endif()
if(NO_ML)
add_compile_definitions(NO_ML)
endif()
if(NO_OBJDETECT)
add_compile_definitions(NO_OBJDETECT)
endif()
if(NO_PHOTO)
add_compile_definitions(NO_PHOTO)
endif()
if(NO_BARCODE)
add_compile_definitions(NO_BARCODE)
add_definitions(-DNO_CONTRIB)
endif()
if(NO_STITCHING)
add_definitions(-DNO_STITCHING)
endif()
if(NO_CALIB3D)
add_definitions(-DNO_CALIB3D)
endif()
if(NO_VIDEO)
add_definitions(-DNO_VIDEO)
endif()
if(NO_FEATURES2D)
add_definitions(-DNO_FEATURES2D)
endif()
if(NO_FLANN)
add_definitions(-DNO_FLANN)
endif()
if(NO_DNN)
add_definitions(-DNO_DNN)
endif()
if(NO_ML)
add_definitions(-DNO_ML)
endif()
if(NO_OBJDETECT)
add_definitions(-DNO_OBJDETECT)
endif()
if(NO_PHOTO)
add_definitions(-DNO_PHOTO)
endif()
if(NO_BARCODE)
add_definitions(-DNO_BARCODE)

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +68
#endif // _WINRT_DLL
#endif // NO_CONTRIB
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #endif comment doesn’t match the opening condition (#ifndef _WINRT_DLL). This is minor, but it makes the preprocessor nesting harder to follow; consider changing it to reflect the actual condition being closed (e.g., “!_WINRT_DLL”).

Copilot uses AI. Check for mistakes.
#pragma endregion

#endif No newline at end of file
#endif // _WINRT_DLL
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #endif comment doesn’t match the opening condition (#ifndef _WINRT_DLL). This is minor, but it makes the preprocessor nesting harder to follow; consider changing it to reflect the actual condition being closed (e.g., “!_WINRT_DLL”).

Suggested change
#endif // _WINRT_DLL
#endif // !_WINRT_DLL

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +12
ROOT_DIR=$(pwd)
INSTALL_PREFIX="/opt/opencv-nocontrib"
RUNTIME_DIR="$ROOT_DIR/runtimes/linux-arm64/native"

Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script assumes it’s run from a directory that contains opencv/, opencv_contrib/, and opencvsharp/ as children because it uses ROOT_DIR=$(pwd). To make it harder to run from the wrong working directory, consider deriving paths from the script location and/or validating that the expected directories exist before continuing.

Copilot uses AI. Check for mistakes.
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