Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/docker-test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:

env:
DEBIAN_FRONTEND: noninteractive
OPENCV_VERSION: 4.13.0
DOCKER_BUILD_CONTEXT_FULL: ./docker/ubuntu24-dotnet10-opencv4.13.0
DOCKER_BUILD_CONTEXT_SLIM: ./docker/ubuntu24-dotnet10-opencv4.13.0-slim
OPENCV_VERSION: 5.0.0
DOCKER_BUILD_CONTEXT_FULL: ./docker/ubuntu24-dotnet10-opencv5.0.0
DOCKER_BUILD_CONTEXT_SLIM: ./docker/ubuntu24-dotnet10-opencv5.0.0-slim

jobs:
build_full:
Expand All @@ -21,16 +21,16 @@ jobs:
steps:
- uses: actions/checkout@v6

- uses: docker/setup-buildx-action@v3
- uses: docker/setup-buildx-action@v4

- name: Build with Docker (full)
uses: docker/build-push-action@v6
uses: docker/build-push-action@v7
with:
context: .
file: ${{ env.DOCKER_BUILD_CONTEXT_FULL }}/Dockerfile
build-args: |
OPENCV_VERSION=${{ env.OPENCV_VERSION }}
outputs: type=docker,name=shimat/ubuntu24-dotnet10-opencv4.13.0:latest
outputs: type=docker,name=shimat/ubuntu24-dotnet10-opencv5.0.0:latest
cache-from: |
type=gha,scope=full-${{ github.ref_name }}
type=gha,scope=full-main
Expand All @@ -43,16 +43,16 @@ jobs:
steps:
- uses: actions/checkout@v6

- uses: docker/setup-buildx-action@v3
- uses: docker/setup-buildx-action@v4

- name: Build with Docker (slim)
uses: docker/build-push-action@v6
uses: docker/build-push-action@v7
with:
context: .
file: ${{ env.DOCKER_BUILD_CONTEXT_SLIM }}/Dockerfile
build-args: |
OPENCV_VERSION=${{ env.OPENCV_VERSION }}
outputs: type=docker,name=shimat/ubuntu24-dotnet10-opencv4.13.0-slim:latest
outputs: type=docker,name=shimat/ubuntu24-dotnet10-opencv5.0.0-slim:latest
cache-from: |
type=gha,scope=slim-${{ github.ref_name }}
type=gha,scope=slim-main
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/linux-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ jobs:
- name: Configure OpenCV
if: steps.opencv-cache.outputs.cache-hit != 'true'
run: |
# Disable the generic ASM language so OpenCV 5's vendored MLAS skips its
# ASM kernels and reports MLAS unavailable (DNN falls back to its
# built-in SGEMM). On aarch64 the MLAS FP16/GQA path references
# MlasHGemmSupported(), which OpenCV 5.0.0 declares and calls but never
# defines, breaking the extern link with an undefined reference.
# GCC 12+ builds libjpeg-turbo/libpng SIMD via NEON intrinsics (not GAS),
# so dropping the ASM compiler does not affect the image codecs here.
cmake \
-G Ninja \
-C cmake/opencv_build_options.cmake \
-S opencv \
-B opencv/build \
-D OPENCV_EXTRA_MODULES_PATH=${GITHUB_WORKSPACE}/opencv_contrib/modules \
-D CMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/opencv_artifacts \
-D CMAKE_ASM_COMPILER="" \
2>&1 | tee /tmp/opencv-configure.log

- name: Verify OpenCV cmake features
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/manylinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,13 @@ jobs:
-S src \
-B src/build-slim \
-D CMAKE_BUILD_TYPE=Release \
-D OpenCV_DIR=${GITHUB_WORKSPACE}/opencv_artifacts_slim/lib64/cmake/opencv4 \
-D OpenCV_DIR=${GITHUB_WORKSPACE}/opencv_artifacts_slim/lib64/cmake/opencv5 \
-D CMAKE_PREFIX_PATH=${GITHUB_WORKSPACE}/opencv_artifacts_slim \
-D NO_CONTRIB=ON \
-D NO_VIDEOIO=ON \
-D NO_HIGHGUI=ON \
-D NO_DNN=ON
-D NO_DNN=ON \
-D NO_STITCHING=ON
cmake --build src/build-slim -j
cp src/build-slim/OpenCvSharpExtern/libOpenCvSharpExtern.so ${GITHUB_WORKSPACE}/libOpenCvSharpExtern-slim.so

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
-DBUILD_opencv_objc_bindings_generator=OFF \
-DBUILD_opencv_rapid=OFF \
-DBUILD_opencv_reg=OFF \
-DBUILD_opencv_stereo=OFF \
-DBUILD_opencv_stereo=ON \
-DBUILD_opencv_structured_light=OFF \
-DBUILD_opencv_surface_matching=OFF \
-DBUILD_opencv_wechat_qrcode=ON \
Expand All @@ -133,7 +133,7 @@ jobs:
cmake --install opencv-${OPENCV_VERSION}/build
em++ -r -o ${GITHUB_WORKSPACE}/opencv_wasm/libopencv.o \
-Wl,--whole-archive ${GITHUB_WORKSPACE}/opencv_wasm/lib/*.a \
${GITHUB_WORKSPACE}/opencv_wasm/lib/opencv4/3rdparty/*.a
${GITHUB_WORKSPACE}/opencv_wasm/lib/opencv5/3rdparty/*.a
ls

- name: Save OpenCV cache
Expand All @@ -150,7 +150,7 @@ jobs:
run: |
ls ${GITHUB_WORKSPACE}/opencv_wasm
echo "-----"
emcmake cmake -S src -B src/build -DCMAKE_BUILD_TYPE=Release -DOpenCV_DIR=${GITHUB_WORKSPACE}/opencv_wasm/lib/cmake/opencv4 -DWASM_LIB=${GITHUB_WORKSPACE}/opencv_wasm/libopencv.o
emcmake cmake -S src -B src/build -DCMAKE_BUILD_TYPE=Release -DOpenCV_DIR=${GITHUB_WORKSPACE}/opencv_wasm/lib/cmake/opencv5 -DWASM_LIB=${GITHUB_WORKSPACE}/opencv_wasm/libopencv.o
cmake --build src/build --parallel $(nproc)
ls src/build/OpenCvSharpExtern
cp src/build/OpenCvSharpExtern/libOpenCvSharpExtern.a ${GITHUB_WORKSPACE}/nuget/
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ jobs:
shell: powershell
run: |
$ErrorActionPreference = 'Continue'
# Force OpenCV 5's vendored MLAS off by giving CMake no ASM compiler
# (see -D CMAKE_ASM_COMPILER below). MinGW or Strawberry-Perl gcc on the
# runner PATH would otherwise be picked by MLAS's check_language(ASM),
# building GNU-syntax .S SGEMM kernels that fail the MSVC link (x64:
# missing SgemmKernelSse2.obj) and inject pthread into the OpenCV link
# interface (arm64: LNK1181 pthread.lib). MLAS then disables and DNN uses
# its built-in SGEMM, matching a clean local VS build. Windows builds the
# image codecs via vcpkg, so no other ASM language is needed.
cmake `
-C cmake/opencv_build_options.cmake `
-S opencv `
Expand All @@ -83,6 +91,7 @@ jobs:
-D "VCPKG_OVERLAY_TRIPLETS=$env:GITHUB_WORKSPACE/cmake/triplets" `
-D OPENCV_EXTRA_MODULES_PATH="$env:GITHUB_WORKSPACE/opencv_contrib/modules" `
-D CMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/opencv_artifacts" `
-D CMAKE_ASM_COMPILER="" `
*>&1 | Tee-Object -FilePath "$env:TEMP\opencv-configure.log"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

Expand Down Expand Up @@ -160,6 +169,7 @@ jobs:
-D NO_VIDEOIO=ON `
-D NO_HIGHGUI=ON `
-D NO_DNN=ON `
-D NO_STITCHING=ON `
-D NO_INSTALL_TO_TEST=ON
cmake --build src/build_slim --config Release -j 4

Expand Down Expand Up @@ -302,6 +312,25 @@ jobs:
shell: powershell
run: |
$ErrorActionPreference = 'Continue'
# Force OpenCV 5's vendored MLAS off by giving CMake no ASM compiler
# (see -D CMAKE_ASM_COMPILER below). MinGW or Strawberry-Perl gcc on the
# runner PATH would otherwise be picked by MLAS's check_language(ASM),
# building GNU-syntax .S SGEMM kernels that fail the MSVC link (x64:
# missing SgemmKernelSse2.obj) and inject pthread into the OpenCV link
# interface (arm64: LNK1181 pthread.lib). MLAS then disables and DNN uses
# its built-in SGEMM, matching a clean local VS build. Windows builds the
# image codecs via vcpkg, so no other ASM language is needed.
# OpenCV 5's vendored MLAS uses GNU-syntax aarch64 .S SGEMM kernels that
# armasm64 (the only ASM compiler on the VS2022 ARM64 toolchain, which
# windows-11-arm ships instead of VS2026) cannot assemble, and
# CMAKE_ASM_COMPILER="" does not disable ASM under the VS ARM64 generator
# (it does under VS2026 x64). MLAS is an OpenCV 5 addition (absent in
# OpenCV 4), so skip building it on this toolchain; DNN keeps working via
# its built-in SGEMM (as OpenCV 4 ARM64 did). Drop the add_subdirectory
# that pulls MLAS into opencv_dnn.
(Get-Content opencv/modules/dnn/CMakeLists.txt) `
-replace 'add_subdirectory\("\$\{OpenCV_SOURCE_DIR\}/3rdparty/mlas".*', '# [win-arm64] MLAS disabled (armasm64 cannot assemble its aarch64 .S kernels)' `
| Set-Content opencv/modules/dnn/CMakeLists.txt
cmake `
-C cmake/opencv_build_options.cmake `
-S opencv `
Expand All @@ -315,6 +344,7 @@ jobs:
-D OPENCV_EXTRA_MODULES_PATH="$env:GITHUB_WORKSPACE/opencv_contrib/modules" `
-D CMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/opencv_artifacts" `
-D WITH_FFMPEG=OFF `
-D CMAKE_ASM_COMPILER="" `
*>&1 | Tee-Object -FilePath "$env:TEMP\opencv-configure.log"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

Expand Down Expand Up @@ -385,6 +415,7 @@ jobs:
-D NO_VIDEOIO=ON `
-D NO_HIGHGUI=ON `
-D NO_DNN=ON `
-D NO_STITCHING=ON `
-D NO_INSTALL_TO_TEST=ON
cmake --build src/build_arm64_slim --config Release -j 4

Expand Down
2 changes: 2 additions & 0 deletions build_opencv_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ if (Test-Path $cmakeCache) {
Write-Host "Removing stale CMakeCache.txt ..."
Remove-Item $cmakeCache -Force
}

cmake `
-C "$RepoRoot/cmake/opencv_build_options.cmake" `
-S "$RepoRoot/opencv" `
Expand All @@ -126,6 +127,7 @@ cmake `
-D "CMAKE_GENERATOR_INSTANCE=$vsInstallPath" `
-D "CMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" `
-D "VCPKG_TARGET_TRIPLET=x64-windows-static" `
-D "VCPKG_MANIFEST_DIR=$RepoRoot" `
-D "VCPKG_INSTALLED_DIR=$vcpkgInstalledDir" `
-D "VCPKG_OVERLAY_TRIPLETS=$RepoRoot/cmake/triplets" `
-D "OPENCV_EXTRA_MODULES_PATH=$RepoRoot/opencv_contrib/modules" `
Expand Down
4 changes: 3 additions & 1 deletion cmake/opencv_build_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ set(BUILD_opencv_mcc OFF CACHE BOOL "" FORCE)
set(BUILD_opencv_objc_bindings_generator OFF CACHE BOOL "" FORCE)
set(BUILD_opencv_rapid OFF CACHE BOOL "" FORCE)
set(BUILD_opencv_reg OFF CACHE BOOL "" FORCE)
set(BUILD_opencv_stereo OFF CACHE BOOL "" FORCE)
# OpenCV 5: calib3d was split and StereoMatcher/StereoBM/StereoSGBM now live in
# the main "stereo" module, so it must be built (ximgproc/disparity_filter needs it).
set(BUILD_opencv_stereo ON CACHE BOOL "" FORCE)
set(BUILD_opencv_structured_light OFF CACHE BOOL "" FORCE)
set(BUILD_opencv_surface_matching OFF CACHE BOOL "" FORCE)
set(BUILD_opencv_videostab OFF CACHE BOOL "" FORCE)
Expand Down
21 changes: 19 additions & 2 deletions cmake/opencv_build_options_slim.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,25 @@ set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(ENABLE_CXX11 ON CACHE BOOL "" FORCE)

# Restrict to a minimal module subset
set(BUILD_LIST "core,imgproc,imgcodecs,calib3d,features2d,flann,objdetect,photo,ml,video,stitching,barcode" CACHE STRING "" FORCE)
# Restrict to a minimal module subset.
# OpenCV 5 module renames vs 4.x:
# - calib3d was split into geometry (2D/3D primitives: convexHull, solvePnP,
# findHomography, ...), calib (camera calibration) and stereo (StereoBM/SGBM)
# - features2d was renamed to features
# - barcode was merged into objdetect (no standalone module anymore)
# - CascadeClassifier / HOGDescriptor / groupRectangles moved to the contrib
# xobjdetect module (lightweight: depends only on core/imgproc/imgcodecs/
# features), kept in the slim profile. Pulled from OPENCV_EXTRA_MODULES_PATH.
# - BRISK / KAZE / AKAZE / AGAST / FREAK / BRIEF / DAISY / ... moved to the
# contrib xfeatures2d module. Its required deps (core/imgproc/features/
# geometry) are all in this list and it pulls no heavy external dependency,
# so it is kept in the slim profile too.
# Additional lightweight contrib kept in slim (deps all in this list, no heavy
# external dependency): ximgproc, xphoto, bgsegm, img_hash.
# stitching is dropped from slim (large, niche); the extern is built with
# NO_STITCHING=ON to match.
# Dependencies of whitelisted modules are added automatically.
set(BUILD_LIST "core,imgproc,imgcodecs,geometry,calib,stereo,features,flann,objdetect,photo,ml,video,xobjdetect,xfeatures2d,ximgproc,xphoto,bgsegm,img_hash" CACHE STRING "" FORCE)

# Disable DNN and Protobuf (not needed in slim profile)
set(BUILD_opencv_dnn OFF CACHE BOOL "" FORCE)
Expand Down
3 changes: 2 additions & 1 deletion docker/ubuntu24-dotnet10-opencv5.0.0-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ RUN --mount=type=cache,target=/root/.ccache \
-D NO_CONTRIB=ON \
-D NO_VIDEOIO=ON \
-D NO_HIGHGUI=ON \
-D NO_DNN=ON; \
-D NO_DNN=ON \
-D NO_STITCHING=ON; \
cmake --build /opencvsharp/make --parallel "$(nproc)"; \
cmake --install /opencvsharp/make; \
rm -rf /opencv /opencv_contrib; \
Expand Down
22 changes: 20 additions & 2 deletions docs/migration-4-to-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,27 @@ working — but you no longer need a separate extensions package for it.

## 3. Removed APIs

| Removed | Replacement |
These wrap OpenCV functions that were removed in OpenCV 5 (no replacement), so
the managed methods are gone too:

| Removed | Notes / replacement |
|---|---|
| `OpenCvSharp.Extensions.Binarizer` (Niblack/Sauvola/Bernsen/Nick/…) | Use `CvXImgProc.NiblackThreshold` (Niblack / Sauvola / Wolf / Nick) |
| `CvDnn.ReadNetFromDarknet`, `CvDnn.ReadNetFromCaffe`, `CvDnn.ReadNetFromTorch`, `CvDnn.ReadTorchBlob`, `CvDnn.ShrinkCaffeModel` (and the `Net.*` equivalents) | Darknet/Caffe/Torch parsers removed — export to ONNX and use `CvDnn.ReadNetFromONNX` |
| `Net.SetHalideScheduler` | Halide backend removed |
| `Cv2.ConvertFp16` | Use `Mat.ConvertTo` to/from `MatType.CV_16F` |
| `Cv2.LogPolar`, `Cv2.LinearPolar` | Use `Cv2.WarpPolar` (`WarpPolarMode.Linear` / `Log`) |
| `Window.GetHandle()`, `Cv2.GetWindowHandle` | Legacy C API removed; no replacement |
| `TrackerGOTURN` | Removed from OpenCV 5 |

## 3a. Changed signatures

Caffe model support was dropped; these constructors now take ONNX model paths:

| Before (OpenCvSharp4) | After (OpenCvSharp5) |
|---|---|
| `OpenCvSharp.Extensions.Binarizer` (Niblack/Sauvola/Bernsen/Nick/…) | OpenCV `ximgproc` niBlack threshold — `CvXImgProc.NiblackThreshold` (supports Niblack / Sauvola / Wolf / Nick) |
| `new BarcodeDetector(superResolutionPrototxtPath, superResolutionCaffeModelPath)` | `new BarcodeDetector(superResolutionModelPath = "")` |
| `new WeChatQRCode(detectorPrototxt, detectorCaffe, srPrototxt, srCaffe)` | `new WeChatQRCode(detectorModelPath = "", superResolutionModelPath = "")` |

## 4. OpenCV 5 API changes surfaced through the wrapper

Expand Down
2 changes: 1 addition & 1 deletion opencv
Submodule opencv updated 3571 files
2 changes: 1 addition & 1 deletion opencv_contrib
Submodule opencv_contrib updated 1319 files
26 changes: 0 additions & 26 deletions src/OpenCvSharp/Cv2/Cv2_core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,32 +337,6 @@ public static void ConvertScaleAbs(InputArray src, OutputArray dst, double alpha
dst.Fix();
}

/// <summary>
/// Converts an array to half precision floating number.
///
/// This function converts FP32(single precision floating point) from/to FP16(half precision floating point). CV_16S format is used to represent FP16 data.
/// There are two use modes(src -&gt; dst) : CV_32F -&gt; CV_16S and CV_16S -&gt; CV_32F.The input array has to have type of CV_32F or
/// CV_16S to represent the bit depth.If the input array is neither of them, the function will raise an error.
/// The format of half precision floating point is defined in IEEE 754-2008.
/// </summary>
/// <param name="src">input array.</param>
/// <param name="dst">output array.</param>
public static void ConvertFp16(InputArray src, OutputArray dst)
{
if (src is null)
throw new ArgumentNullException(nameof(src));
if (dst is null)
throw new ArgumentNullException(nameof(dst));
src.ThrowIfDisposed();
dst.ThrowIfNotReady();

NativeMethods.HandleException(
NativeMethods.core_convertFp16(src.CvPtr, dst.CvPtr));

GC.KeepAlive(src);
dst.Fix();
}

/// <summary>
/// transforms array of numbers using a lookup table: dst(i)=lut(src(i))
/// </summary>
Expand Down
14 changes: 0 additions & 14 deletions src/OpenCvSharp/Cv2/Cv2_highgui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,18 +443,4 @@ public static void SetTrackbarMin(string trackbarName, string winName, int minVa
NativeMethods.HandleException(
NativeMethods.highgui_setTrackbarMin(trackbarName, winName, minVal));
}

/// <summary>
/// get native window handle (HWND in case of Win32 and Widget in case of X Window)
/// </summary>
/// <param name="windowName"></param>
public static IntPtr GetWindowHandle(string windowName)
{
if (windowName is null)
throw new ArgumentNullException(nameof(windowName));

NativeMethods.HandleException(
NativeMethods.highgui_cvGetWindowHandle(windowName, out var ret));
return ret;
}
}
Loading
Loading