OpenCV5Sharp.Mobile
1.0.10
dotnet add package OpenCV5Sharp.Mobile --version 1.0.10
NuGet\Install-Package OpenCV5Sharp.Mobile -Version 1.0.10
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenCV5Sharp.Mobile" Version="1.0.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenCV5Sharp.Mobile" Version="1.0.10" />
<PackageReference Include="OpenCV5Sharp.Mobile" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenCV5Sharp.Mobile --version 1.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenCV5Sharp.Mobile, 1.0.10"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenCV5Sharp.Mobile@1.0.10
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenCV5Sharp.Mobile&version=1.0.10
#tool nuget:?package=OpenCV5Sharp.Mobile&version=1.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
OpenCV5Sharp Library
Published by Qourex
Clean, automatic C# wrapper for OpenCV 5.0.0 with complete API coverage and robust unmanaged memory management.
Installation
dotnet add package OpenCV5Sharp
Or via the NuGet Package Manager Console:
Install-Package OpenCV5Sharp
Key Features
- OpenCV 5.0.0 Alignment: Matches the restructured OpenCV 5 API layout (Features module, new Stereo/Calib split, and DNN).
- Auto-Generated Complete API: Over 2,600 methods from
core,imgproc,videoio,highgui,features2d,calib3d,objdetect,photo, anddnnmodules. - Thread-Safe Unmanaged Memory: Uses a specialized, atomic
Interlocked.Exchange-basedDisposableOpenCVObjectbase class to prevent double-free conditions and memory leaks. - Exceptions Boundary Protection: Zero raw native crashes. Every single C++ entry point is wrapped in standard
try/catchhandlers that map exceptions back to managedOpenCVExceptionobjects. - Zero-Configuration Bundling: Prebuilt
opencv_world500.dll,opencv_videoio_ffmpeg500_64.dll, andopencv5sharp_native.dllare bundled and copied automatically to the build output.
Supported Platforms
- Operating System: Windows (x64), Linux (x64), macOS (x64, ARM64), Android (ARM64), iOS (ARM64)
- Frameworks: .NET 8.0, .NET 9.0, .NET 10.0
Quick Start Example
using System;
using OpenCV5Sharp;
class Program
{
static void Main()
{
// 1. Read input image (BGR color)
using (Mat src = Cv2.Imread("input.jpg", (int)ImreadModes.Color))
using (Mat gray = new Mat())
using (Mat blurred = new Mat())
using (Mat edges = new Mat())
{
if (src == null || src.Handle == IntPtr.Zero)
{
Console.WriteLine("Error: Could not load image.");
return;
}
// 2. Convert to Grayscale
Cv2.CvtColor(src, gray, (int)ColorConversionCodes.Bgr2gray, 0, AlgorithmHint.Default);
// 3. Apply a 5x5 Gaussian Blur
Cv2.GaussianBlur(gray, blurred, new Size(5, 5), 1.5, 1.5, (int)BorderTypes.Default, AlgorithmHint.Default);
// 4. Perform Canny Edge Detection
Cv2.Canny(blurred, edges, 50, 150, 3, false);
// 5. Write the processed image back to disk
Cv2.Imwrite("output_edges.jpg", edges, IntPtr.Zero);
} // All unmanaged memory is automatically freed here
}
}
Type Conversion Guide
| OpenCV C++ Type | OpenCV5Sharp Managed Type | Marshaling Details |
|---|---|---|
cv::Mat |
OpenCV5Sharp.Mat |
Wrapped IntPtr to unmanaged C++ instance |
cv::Size_<int> |
OpenCV5Sharp.Size |
Sequential layout struct |
cv::Point_<int> |
OpenCV5Sharp.Point |
Sequential layout struct |
cv::Rect_<int> |
OpenCV5Sharp.Rect |
Sequential layout struct |
cv::Scalar_<double> |
OpenCV5Sharp.Scalar |
Sequential layout struct |
cv::Range |
OpenCV5Sharp.Range |
Sequential layout struct |
cv::TermCriteria |
OpenCV5Sharp.TermCriteria |
Sequential layout struct |
cv::String / std::string |
System.String |
UTF-8 marshaled string |
Error Handling
All C++ exceptions (including OpenCV's native cv::Exception) are caught on the native side and converted into thread-local error states. When a wrapper call fails:
- The native function returns a failure status.
- The managed side detects the failure and fetches the error details.
- An
OpenCVExceptionis thrown containing the native stack trace and error code.
Example:
try
{
using (Mat src = new Mat()) // Empty image
using (Mat dst = new Mat())
{
Cv2.CvtColor(src, dst, (int)ColorConversionCodes.Bgr2gray, 0, AlgorithmHint.Default);
}
}
catch (OpenCVException ex)
{
Console.WriteLine($"OpenCV Error: {ex.Message} (Code: {ex.ErrorCode})");
}
Memory Ownership and Thread Safety
- Explicit Disposal: Any object inheriting from
DisposableOpenCVObject(e.g.Mat,VideoCapture,CLAHE) allocates unmanaged resources. You must dispose them when done, preferably using C#usingblocks. - Double-Free Prevention: Calling
Dispose()multiple times, or havingDispose()race with the Garbage Collector Finalizer, is thread-safe and handled atomically. - Thread Safety: P/Invoke calls are thread-safe and re-entrant. However, mutating a single
Matinstance from multiple threads simultaneously is not synchronized by the library; you must manage instance-level synchronization in user code.
Support & Contact
- GitHub: github.com/qourex/opencv5sharp
- Website: qourex.com
- Email: info@qourex.com
License
- Library Code: Licensed under the Apache License, Version 2.0.
- FFmpeg Integration: Dynamically links to FFmpeg binaries which are licensed under the GNU LGPL v2.1 or later.
- Trademark Notice: "OpenCV" is a registered trademark of the OpenCV Foundation. This project is a separate community wrapper and is not endorsed by or affiliated with the OpenCV Foundation.
<p align="center">Built with ❤️ by <a href="https://qourex.com">Qourex</a></p>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android is compatible. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android is compatible. net9.0-browser was computed. net9.0-ios is compatible. net9.0-maccatalyst is compatible. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android is compatible. net10.0-browser was computed. net10.0-ios is compatible. net10.0-maccatalyst is compatible. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- OpenCV5Sharp (>= 1.0.10)
-
net10.0-android
- OpenCV5Sharp (>= 1.0.10)
-
net10.0-ios
- OpenCV5Sharp (>= 1.0.10)
-
net10.0-maccatalyst
- OpenCV5Sharp (>= 1.0.10)
-
net8.0
- OpenCV5Sharp (>= 1.0.10)
-
net8.0-android
- OpenCV5Sharp (>= 1.0.10)
-
net9.0
- OpenCV5Sharp (>= 1.0.10)
-
net9.0-android
- OpenCV5Sharp (>= 1.0.10)
-
net9.0-ios
- OpenCV5Sharp (>= 1.0.10)
-
net9.0-maccatalyst
- OpenCV5Sharp (>= 1.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.10 | 47 | 7/2/2026 |
See CHANGELOG.md for release notes.