|
| 1 | +# Installation |
| 2 | + |
| 3 | +This page creates a .NET console application and installs the packages selected in [Choose a Version and Package](package-selection.md). The commands require the [.NET 8 SDK or later](https://dotnet.microsoft.com/download). |
| 4 | + |
| 5 | +## Create a project |
| 6 | + |
| 7 | +```bash |
| 8 | +dotnet new console -n OpenCvSharpExample |
| 9 | +cd OpenCvSharpExample |
| 10 | +``` |
| 11 | + |
| 12 | +## Windows x64 |
| 13 | + |
| 14 | +The all-in-one package is the simplest option for Windows x64: |
| 15 | + |
| 16 | +```bash |
| 17 | +dotnet add package OpenCvSharp5.Windows |
| 18 | +``` |
| 19 | + |
| 20 | +For the reduced module set, use `OpenCvSharp5.Windows.Slim` instead. |
| 21 | + |
| 22 | +## Windows ARM64 |
| 23 | + |
| 24 | +```bash |
| 25 | +dotnet add package OpenCvSharp5 |
| 26 | +dotnet add package OpenCvSharp5.runtime.win-arm64 |
| 27 | +``` |
| 28 | + |
| 29 | +Use `OpenCvSharp5.runtime.win-arm64.slim` instead of the full runtime when the reduced module set is sufficient. |
| 30 | + |
| 31 | +## Linux x64 |
| 32 | + |
| 33 | +For a desktop application that uses native OpenCV windows: |
| 34 | + |
| 35 | +```bash |
| 36 | +dotnet add package OpenCvSharp5 |
| 37 | +dotnet add package OpenCvSharp5.official.runtime.linux-x64 |
| 38 | +``` |
| 39 | + |
| 40 | +For a service or container that does not use `Cv2.ImShow`, `Cv2.WaitKey`, or other `highgui` APIs: |
| 41 | + |
| 42 | +```bash |
| 43 | +dotnet add package OpenCvSharp5 |
| 44 | +dotnet add package OpenCvSharp5.official.runtime.linux-x64.headless |
| 45 | +``` |
| 46 | + |
| 47 | +The full runtime requires GTK3. On a minimal Ubuntu or Debian installation, install it with: |
| 48 | + |
| 49 | +```bash |
| 50 | +sudo apt-get update |
| 51 | +sudo apt-get install libgtk-3-0 |
| 52 | +``` |
| 53 | + |
| 54 | +The official Linux x64 packages require glibc 2.28 or later. |
| 55 | + |
| 56 | +## Linux ARM64 |
| 57 | + |
| 58 | +```bash |
| 59 | +dotnet add package OpenCvSharp5 |
| 60 | +dotnet add package OpenCvSharp5.runtime.linux-arm64 |
| 61 | +``` |
| 62 | + |
| 63 | +## macOS |
| 64 | + |
| 65 | +For Apple Silicon: |
| 66 | + |
| 67 | +```bash |
| 68 | +dotnet add package OpenCvSharp5 |
| 69 | +dotnet add package OpenCvSharp5.runtime.osx.arm64 |
| 70 | +``` |
| 71 | + |
| 72 | +For an Intel Mac: |
| 73 | + |
| 74 | +```bash |
| 75 | +dotnet add package OpenCvSharp5 |
| 76 | +dotnet add package OpenCvSharp5.runtime.osx.x64 |
| 77 | +``` |
| 78 | + |
| 79 | +## WebAssembly |
| 80 | + |
| 81 | +WebAssembly uses static native linking and requires a Blazor WebAssembly project rather than the console project created above. Install the WebAssembly build tools and create a standalone Blazor WebAssembly application: |
| 82 | + |
| 83 | +```bash |
| 84 | +dotnet workload install wasm-tools |
| 85 | +dotnet new blazorwasm -n OpenCvSharpWasmExample |
| 86 | +cd OpenCvSharpWasmExample |
| 87 | +dotnet add package OpenCvSharp5 |
| 88 | +dotnet add package OpenCvSharp5.runtime.wasm |
| 89 | +``` |
| 90 | + |
| 91 | +Add the following properties to the project file: |
| 92 | + |
| 93 | +```xml |
| 94 | +<PropertyGroup> |
| 95 | + <WasmInitialHeapSize>268435456</WasmInitialHeapSize> |
| 96 | + <WasmAllowUndefinedSymbols>true</WasmAllowUndefinedSymbols> |
| 97 | +</PropertyGroup> |
| 98 | +``` |
| 99 | + |
| 100 | +The larger initial heap accommodates the statically linked OpenCV runtime. `WasmAllowUndefinedSymbols` is currently a package and toolchain-specific linker workaround: it allows the static link to complete even though the managed assembly declares APIs for OpenCV modules that are not included in the WebAssembly build. Calling one of those unavailable APIs will still fail at run time. This property does not configure exception handling; the runtime package supplies the native archive and its required `WasmEnableExceptionHandling` setting. |
| 101 | + |
| 102 | +See the [OpenCvSharp Blazor sample](https://github.com/shimat/opencvsharp_blazor_sample) for a complete browser application. |
| 103 | + |
| 104 | +## Verify the package references |
| 105 | + |
| 106 | +```bash |
| 107 | +dotnet list package |
| 108 | +dotnet restore |
| 109 | +dotnet build |
| 110 | +``` |
| 111 | + |
| 112 | +The package list should contain `OpenCvSharp5` and exactly one runtime package for the deployment target, unless you selected a Windows convenience package. |
| 113 | + |
| 114 | +## Next step |
| 115 | + |
| 116 | +Continue to [Your First Application](first-application.md). |
0 commit comments