Skip to content

Commit 509ed5d

Browse files
authored
Merge pull request #1810 from shimat/readme_update
update README.md
2 parents e0403fc + d678862 commit 509ed5d

2 files changed

Lines changed: 84 additions & 65 deletions

File tree

README.md

Lines changed: 83 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,51 @@
22

33
[![Github Actions Windows Status](https://github.com/shimat/opencvsharp/workflows/Windows%20Server%202025/badge.svg)](https://github.com/shimat/opencvsharp/actions) [![Github Actions Ubuntu 22.04 Status](https://github.com/shimat/opencvsharp/workflows/Ubuntu%2022.04/badge.svg)](https://github.com/shimat/opencvsharp/actions) [![Github Actions Ubuntu 24.04 Status](https://github.com/shimat/opencvsharp/workflows/Ubuntu%2024.04/badge.svg)](https://github.com/shimat/opencvsharp/actions) [![GitHub license](https://img.shields.io/github/license/shimat/opencvsharp.svg)](https://github.com/shimat/opencvsharp/blob/master/LICENSE)
44

5-
Old versions of OpenCvSharp are stored in [opencvsharp_2410](https://github.com/shimat/opencvsharp_2410).
5+
OpenCvSharp is a cross-platform .NET wrapper for OpenCV, providing a rich set of image processing and computer vision functionality. It supports .NET Framework 4.8, .NET 8 and later, and .NET Standard 2.0.
66

7-
## NuGet
7+
## Quick Start
88

9-
### Managed libraries
10-
| Package | Description | Link |
11-
|---------|-------------|------|
12-
|**OpenCvSharp4**| OpenCvSharp core libraries | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.svg)](https://badge.fury.io/nu/OpenCvSharp4) |
13-
|**OpenCvSharp4.Extensions**| GDI+ Extensions | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.Extensions.svg)](https://badge.fury.io/nu/OpenCvSharp4.Extensions) |
14-
|**OpenCvSharp4.WpfExtensions**| WPF Extensions | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.WpfExtensions.svg)](https://badge.fury.io/nu/OpenCvSharp4.WpfExtensions) |
15-
|**OpenCvSharp4.Windows**| All-in-one package for Windows (except UWP) | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.Windows.svg)](https://badge.fury.io/nu/OpenCvSharp4.Windows) |
9+
### Windows
10+
```bash
11+
dotnet add package OpenCvSharp4.Windows
12+
```
1613

17-
### Native bindings
18-
| Package | Description | Link |
19-
|---------|-------------|------|
20-
|**OpenCvSharp4.runtime.win**| Native bindings for Windows x64/x86 (except UWP) | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.runtime.win.svg)](https://badge.fury.io/nu/OpenCvSharp4.runtime.win) |
21-
|**OpenCvSharp4.runtime.uwp**| Native bindings for UWP (Universal Windows Platform) x64/x86/ARM | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.runtime.uwp.svg)](https://badge.fury.io/nu/OpenCvSharp4.runtime.uwp) |
22-
|**OpenCvSharp4.official.runtime.linux-x64**| Native bindings for Linux x64 (built on Ubuntu 24.04) | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.linux-x64.svg)](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.linux-x64) |
23-
|**OpenCvSharp4.official.runtime.ubuntu.22.04-x64**| Native bindings for Ubuntu 22.04 x64 | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.ubuntu.22.04-x64.svg)](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.ubuntu.22.04-x64) |
24-
|**OpenCvSharp4.official.runtime.ubuntu.24.04-x64**| Native bindings for Ubuntu 24.04 x64 | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.ubuntu.24.04-x64.svg)](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.ubuntu.24.04-x64) |
25-
|**OpenCvSharp4.runtime.linux-arm**| Native bindings for Linux Arm | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.runtime.linux-arm.svg)](https://www.nuget.org/packages/OpenCvSharp4.runtime.linux-arm/) |
26-
|**OpenCvSharp4.runtime.wasm**| Native bindings for WebAssembly | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.runtime.wasm.svg)](https://www.nuget.org/packages/OpenCvSharp4.runtime.wasm/) |
14+
### Linux / Ubuntu
15+
```bash
16+
dotnet add package OpenCvSharp4
17+
dotnet add package OpenCvSharp4.official.runtime.ubuntu.24.04-x64
18+
```
2719

28-
Native binding (OpenCvSharpExtern.dll / libOpenCvSharpExtern.so) is required to work OpenCvSharp. To use OpenCvSharp, you should add both `OpenCvSharp4` and `OpenCvSharp4.runtime.*` packages to your project. Currently, native bindings for Windows, UWP, Ubuntu, Linux ARM, and WebAssembly are released.
20+
For more installation options, see the [Installation](#installation) section below.
2921

30-
Packages named OpenCvSharp3-* and OpenCvSharp-* are deprecated.
31-
> [OpenCvSharp3-AnyCPU](https://www.nuget.org/packages/OpenCvSharp3-AnyCPU/) / [OpenCvSharp3-WithoutDll](https://www.nuget.org/packages/OpenCvSharp3-WithoutDll/) / [OpenCvSharp-AnyCPU](https://www.nuget.org/packages/OpenCvSharp-AnyCPU/) / [OpenCvSharp-WithoutDll](https://www.nuget.org/packages/OpenCvSharp-WithoutDll/)
22+
## Features
23+
* OpenCvSharp is modeled on the native OpenCV C/C++ API style as much as possible.
24+
* Many classes of OpenCvSharp implement IDisposable. Unsafe resources are managed automatically.
25+
* OpenCvSharp does not force object-oriented programming style on you. You can also call native-style OpenCV functions.
26+
* OpenCvSharp provides functions for converting from `Mat` to `Bitmap` (GDI+) or `WriteableBitmap` (WPF).
27+
28+
## Target OpenCV
29+
* [OpenCV 4.13.0](https://opencv.org/) with [opencv_contrib](https://github.com/opencv/opencv_contrib)
30+
31+
## Requirements
32+
* [.NET Framework 4.8](http://www.microsoft.com/ja-jp/download/details.aspx?id=1639) / [.NET 8](https://www.microsoft.com/net/download) or later / .NET Standard 2.0
33+
* (Windows) [Visual C++ 2022 Redistributable Package](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads)
34+
* (Windows Server) Media Foundation
35+
```
36+
PS1> Install-WindowsFeature Server-Media-Foundation
37+
```
38+
* (Ubuntu) You must pre-install all the dependency packages needed to build OpenCV. Many packages such as libjpeg must be installed for OpenCV to work.
39+
https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
3240

33-
## Docker images
34-
https://github.com/shimat?tab=packages
41+
42+
**OpenCvSharp won't work on Unity and Xamarin platforms.** For Unity, please consider using [OpenCV for Unity](https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088) or some other solutions.
43+
44+
**OpenCvSharp does not support CUDA.** If you want to use CUDA features, you need to customize the native bindings yourself.
3545

3646
## Installation
3747

3848
### Windows (except UWP)
39-
Add `OpenCvSharp4` and `OpenCvSharp4.runtime.win` NuGet packages to your project. You can use `OpenCvSharp4.Windows` instead.
49+
Add `OpenCvSharp4` and `OpenCvSharp4.runtime.win` NuGet packages to your project. Alternatively, you can use the `OpenCvSharp4.Windows` all-in-one package.
4050

4151
### UWP
4252
Add `OpenCvSharp4` and `OpenCvSharp4.runtime.uwp` NuGet packages to your project. Note that `OpenCvSharp4.runtime.win` and `OpenCvSharp4.Windows` don't work for UWP.
@@ -74,31 +84,10 @@ dotnet add package OpenCvSharp4.official.runtime.linux-x64
7484
dotnet run
7585
```
7686

77-
### Downloads
78-
If you do not use NuGet, get DLL files from the [release page](https://github.com/shimat/opencvsharp/releases).
79-
80-
## Target OpenCV
81-
* [OpenCV 4.13.0](https://opencv.org/) with [opencv_contrib](https://github.com/opencv/opencv_contrib)
82-
83-
## Requirements
84-
* [.NET Framework 4.8](http://www.microsoft.com/ja-jp/download/details.aspx?id=1639) / [.NET 8](https://www.microsoft.com/net/download) or later / .NET Standard 2.0
85-
* (Windows) [Visual C++ 2022 Redistributable Package](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads)
86-
* (Windows Server) Media Foundation
87-
```
88-
PS1> Install-WindowsFeature Server-Media-Foundation
89-
```
90-
* (Ubuntu) You must pre-install all the dependency packages needed to build OpenCV. Many packages such as libjpeg must be installed in order to work OpenCV.
91-
https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
92-
93-
94-
**OpenCvSharp won't work on Unity and Xamarin platform.** For Unity, please consider using [OpenCV for Unity](https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088) or some other solutions.
95-
96-
**OpenCvSharp does not support CUDA.** If you want to use the CUDA features, you need to customize the native bindings yourself.
97-
9887
## Usage
99-
For more details, see **[samples](https://github.com/shimat/opencvsharp_samples/)** and **[Wiki](https://github.com/shimat/opencvsharp/wiki)** pages.
88+
For more details, refer to the **[samples](https://github.com/shimat/opencvsharp_samples/)** and **[Wiki](https://github.com/shimat/opencvsharp/wiki)** pages.
10089

101-
**Always remember to release Mat instances! The `using` syntax is useful.**
90+
**Always remember to release Mat and other IDisposable resources using the `using` syntax:**
10291
```C#
10392
// C# 8
10493
// Edge detection by Canny algorithm
@@ -109,7 +98,7 @@ class Program
10998
static void Main()
11099
{
111100
using var src = new Mat("lenna.png", ImreadModes.Grayscale);
112-
       using var dst = new Mat();
101+
using var dst = new Mat();
113102

114103
Cv2.Canny(src, dst, 50, 200);
115104
using (new Window("src image", src))
@@ -121,9 +110,12 @@ class Program
121110
}
122111
```
123112

124-
As mentioned above, objects of classes, such as Mat and MatExpr, have unmanaged resources and need to be manually released by calling the Dispose() method. Worst of all, the +, -, *, and other operators create new objects each time, and these objects need to be disposed, or there will be memory leaks. Despite having the using syntax, the code still looks very verbose.
113+
<details>
114+
<summary><b>Advanced: Using ResourcesTracker for automatic resource management</b></summary>
125115

126-
Therefore, a ResourcesTracker class is provided. The ResourcesTracker implements the IDisposable interface, and when the Dispose() method is called, all resources tracked by the ResourcesTracker are disposed. The T() method of ResourcesTracker can trace an object or an array of objects, and the method NewMat() is like T(new Mat(...). All the objects that need to be released can be wrapped with T().For example: t.T(255 - t.T(picMat * 0.8)) . Example code is as following:
116+
As mentioned above, objects of classes such as Mat and MatExpr have unmanaged resources and need to be manually released by calling the Dispose() method. Additionally, the +, -, *, and other operators create new objects each time, and these objects need to be disposed to prevent memory leaks. Despite having the using syntax, the code can still look verbose.
117+
118+
Therefore, a ResourcesTracker class is provided. The ResourcesTracker implements the IDisposable interface, and when the Dispose() method is called, all resources tracked by the ResourcesTracker are disposed. The T() method of ResourcesTracker can track an object or an array of objects, and the NewMat() method is equivalent to T(new Mat(...)). All objects that need to be released can be wrapped with T(). For example: t.T(255 - t.T(picMat * 0.8)). Example code is as follows:
127119

128120
```csharp
129121
using (var t = new ResourcesTracker())
@@ -147,20 +139,48 @@ using (var t = new ResourcesTracker())
147139
}
148140
```
149141

150-
151-
## Features
152-
* OpenCvSharp is modeled on the native OpenCV C/C++ API style as much as possible.
153-
* Many classes of OpenCvSharp implement IDisposable. There is no need to manage unsafe resources.
154-
* OpenCvSharp does not force object-oriented programming style on you. You can also call native-style OpenCV functions.
155-
* OpenCvSharp provides functions for converting from `Mat` into `Bitmap`(GDI+) or `WriteableBitmap`(WPF).
142+
</details>
156143

157144
## Code samples
158145
https://github.com/shimat/opencvsharp_samples/
159146

160147
## API Documents
161148
http://shimat.github.io/opencvsharp/api/OpenCvSharp.html
162149

150+
## NuGet
151+
152+
### Managed libraries
153+
| Package | Description | Link |
154+
|---------|-------------|------|
155+
|**OpenCvSharp4**| OpenCvSharp core libraries | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.svg)](https://badge.fury.io/nu/OpenCvSharp4) |
156+
|**OpenCvSharp4.Extensions**| GDI+ Extensions | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.Extensions.svg)](https://badge.fury.io/nu/OpenCvSharp4.Extensions) |
157+
|**OpenCvSharp4.WpfExtensions**| WPF Extensions | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.WpfExtensions.svg)](https://badge.fury.io/nu/OpenCvSharp4.WpfExtensions) |
158+
|**OpenCvSharp4.Windows**| All-in-one package for Windows (except UWP) | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.Windows.svg)](https://badge.fury.io/nu/OpenCvSharp4.Windows) |
159+
160+
### Native bindings
161+
| Package | Description | Link |
162+
|---------|-------------|------|
163+
|**OpenCvSharp4.runtime.win**| Native bindings for Windows x64/x86 (except UWP) | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.runtime.win.svg)](https://badge.fury.io/nu/OpenCvSharp4.runtime.win) |
164+
|**OpenCvSharp4.runtime.uwp**| Native bindings for UWP (Universal Windows Platform) x64/x86/ARM | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.runtime.uwp.svg)](https://badge.fury.io/nu/OpenCvSharp4.runtime.uwp) |
165+
|**OpenCvSharp4.official.runtime.linux-x64**| Native bindings for Linux x64 (built on Ubuntu 24.04) | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.linux-x64.svg)](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.linux-x64) |
166+
|**OpenCvSharp4.official.runtime.ubuntu.22.04-x64**| Native bindings for Ubuntu 22.04 x64 | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.ubuntu.22.04-x64.svg)](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.ubuntu.22.04-x64) |
167+
|**OpenCvSharp4.official.runtime.ubuntu.24.04-x64**| Native bindings for Ubuntu 24.04 x64 | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.ubuntu.24.04-x64.svg)](https://badge.fury.io/nu/OpenCvSharp4.official.runtime.ubuntu.24.04-x64) |
168+
|**OpenCvSharp4.runtime.linux-arm**| Native bindings for Linux Arm | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.runtime.linux-arm.svg)](https://www.nuget.org/packages/OpenCvSharp4.runtime.linux-arm/) |
169+
|**OpenCvSharp4.runtime.wasm**| Native bindings for WebAssembly | [![NuGet version](https://badge.fury.io/nu/OpenCvSharp4.runtime.wasm.svg)](https://www.nuget.org/packages/OpenCvSharp4.runtime.wasm/) |
170+
171+
Native binding (OpenCvSharpExtern.dll / libOpenCvSharpExtern.so) is required for OpenCvSharp to work. To use OpenCvSharp, you should add both `OpenCvSharp4` and `OpenCvSharp4.runtime.*` packages to your project. Currently, native bindings for Windows, UWP, Ubuntu, Linux ARM, and WebAssembly are available.
172+
173+
Packages named OpenCvSharp3-* and OpenCvSharp-* are deprecated.
174+
> [OpenCvSharp3-AnyCPU](https://www.nuget.org/packages/OpenCvSharp3-AnyCPU/) / [OpenCvSharp3-WithoutDll](https://www.nuget.org/packages/OpenCvSharp3-WithoutDll/) / [OpenCvSharp-AnyCPU](https://www.nuget.org/packages/OpenCvSharp-AnyCPU/) / [OpenCvSharp-WithoutDll](https://www.nuget.org/packages/OpenCvSharp-WithoutDll/)
175+
176+
## Downloads
177+
If you are not using NuGet, you can download the DLL files from the [release page](https://github.com/shimat/opencvsharp/releases).
178+
179+
## Docker images
180+
https://github.com/shimat?tab=packages
181+
163182
## OpenCvSharp Build Instructions
183+
164184
### Windows
165185
- Install Visual Studio 2022 or later
166186
- VC++ features are required.
@@ -172,16 +192,15 @@ http://shimat.github.io/opencvsharp/api/OpenCvSharp.html
172192
- Open `OpenCvSharp.sln` and build
173193

174194
#### How to customize OpenCV binaries yourself
175-
If you want to use some OpenCV features that are not provided by default in OpenCvSharp (e.g. GPU), you will have to build OpenCV yourself. The binary files of OpenCV for OpenCvSharp for Windows are created in the [opencv_files](https://github.com/shimat/opencv_files) repository. See the README.
195+
If you want to use OpenCV features that are not included by default in OpenCvSharp (e.g., GPU support), you will need to build OpenCV yourself. The binary files of OpenCV for OpenCvSharp for Windows are created in the [opencv_files](https://github.com/shimat/opencv_files) repository. See the README for details.
176196

177197
- `git clone --recursive https://github.com/shimat/opencv_files`
178-
- Edit `build_windows.ps1` or `build_uwp.ps1` to customize the CMake parameters .
179-
- Run the PowerShell script.
198+
- Edit `build_windows.ps1` or `build_uwp.ps1` to customize the CMake parameters
199+
- Run the PowerShell script
180200

181201
### Ubuntu
182-
- Build OpenCV with opencv_contrib.
183-
- https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
184-
- Install .NET Core SDK. https://learn.microsoft.com/ja-jp/dotnet/core/install/linux-ubuntu
202+
- Build OpenCV with opencv_contrib: https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
203+
- Install .NET Core SDK: https://learn.microsoft.com/ja-jp/dotnet/core/install/linux-ubuntu
185204
- Get OpenCvSharp source files
186205
```
187206
git clone https://github.com/shimat/opencvsharp.git
@@ -198,7 +217,7 @@ cmake -D CMAKE_INSTALL_PREFIX=${YOUR_OPENCV_INSTALL_PATH} ..
198217
make -j
199218
make install
200219
```
201-
You should add reference to `opencvsharp/src/build/OpenCvSharpExtern/libOpenCvSharpExtern.so`
220+
You should add a reference to `opencvsharp/src/build/OpenCvSharpExtern/libOpenCvSharpExtern.so`
202221
```
203222
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/home/shimat/opencvsharp/src/build/OpenCvSharpExtern"
204223
```

test/OpenCvSharp.Tests/imgproc/ImgProcTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public void FitEllipseAMS()
304304
Assert.Equal(20f, ellipse.Size.Height, 4e-1);
305305

306306
var angleError = Math.Min(Math.Abs(ellipse.Angle), Math.Abs(ellipse.Angle - 180f));
307-
Assert.True(angleError < 5e-1, $"Angle should be close to 0 or 180 degrees, but was {ellipse.Angle}");
307+
Assert.True(angleError < 1.0, $"Angle should be close to 0 or 180 degrees, but was {ellipse.Angle}");
308308
}
309309

310310
[Fact]

0 commit comments

Comments
 (0)