Skip to content

Commit db80610

Browse files
committed
create win-opencv content
1 parent dec3dfd commit db80610

File tree

6 files changed

+512
-0
lines changed

6 files changed

+512
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: OpenCV and Compilers
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## OpenCV
10+
OpenCV (Open Source Computer Vision Library) is a popular, open-source library that developers use to build computer vision applications. It provides a set of tools and functions that help you handle tasks related to images and videos without needing to write everything from scratch.
11+
12+
Here’s what developers should know:
13+
14+
* __Ease of Use__: OpenCV comes with pre-built functions for common tasks like reading, displaying, and processing images and videos. This saves time compared to writing algorithms from the ground up.
15+
16+
* __Image Processing__: You can perform operations like changing colors, applying filters, resizing, rotating, and other transformations to images with minimal code.
17+
18+
* __Video Handling__: Developers can use OpenCV to capture, modify, and analyze video frames, making it ideal for creating applications like video surveillance or video editing tools.
19+
20+
* __Computer Vision Algorithms__: OpenCV includes built-in algorithms for complex tasks like object detection (e.g., face and eye recognition), edge detection, and image segmentation.
21+
22+
* __Machine Learning__: It includes modules for training models using basic machine learning algorithms, which can be applied for pattern recognition and data analysis in visual data.
23+
24+
* __Community and Resources__: Being open-source and widely adopted, there is a large community of developers contributing to and supporting OpenCV. This makes it easier to find tutorials, documentation, and answers to questions.
25+
26+
27+
## Compilers for Windows on Arm Development
28+
29+
When building applications for Windows on Arm, both MSVC (Microsoft Visual C++) and Clang are options for developers, each with its own advantages.
30+
31+
* __MSVC__: A compiler developed by Microsoft that’s part of the Visual Studio IDE. It’s designed specifically for Windows and integrates well with the Windows development ecosystem.
32+
33+
* __Clang__: An open-source compiler that is part of the LLVM project. It’s known for its modern design and and cross-platform capabilities.
34+
35+
MSVC is the go-to for Windows-focused projects needing seamless integration with Visual Studio. Clang is ideal for cross-platform projects or when using modern C++ features with flexibility.
36+
37+
## Before you begin
38+
39+
Any Windows on Arm computer which has the required tools installed can be used for this Learning Path. You will learn the build methods using both MSVC and Clang.
40+
41+
Please install the following tools required for both methods.
42+
43+
* [CMake](/install-guides/cmake)
44+
45+
{{% notice Note %}}
46+
The instructions were tested with the version 3.28.1
47+
{{% /notice %}}
48+
49+
* [Git](https://git-scm.com/downloads/win)
50+
51+
{{% notice Note %}}
52+
There is currently no Arm version of Git. Install the 64-bit x86 version.
53+
{{% /notice %}}
54+
55+
Follow the link to intall the required tools for a method using MSVC.
56+
57+
* [Visual Studio 2022 or higher](/install-guides/vs-woa).
58+
59+
{{% notice Note %}}
60+
The instructions were tested with Visual Studio 2022.
61+
{{% /notice %}}
62+
63+
To build using Clang, please install the following.
64+
65+
* [LLVM](install-guides/llvm-woa/)
66+
67+
{{% notice Note %}}
68+
The instructions were tested with the version 18.1.8.
69+
{{% /notice %}}
70+
71+
* [Ninja]( https://github.com/ninja-build/ninja/releases)
72+
73+
{{% notice Note %}}
74+
The instructions were tested with version 1.11.1
75+
{{% /notice %}}
76+
77+
You use the LLVM Clang and the Ninja generator to build. Set PATH to the paths to your LLVM and Ninja install.
78+
79+
You now have the required development tools installed.Please proceed to the page for the compiler you want to build with.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
title: Build OpenCV Applications with MSVC
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Build OpenCV with MSVC
10+
11+
### Clone OpenCV repo
12+
13+
Open up a Windows Powershell and checkout the source tree:
14+
15+
```bash
16+
git clone https://github.com/opencv/opencv
17+
cd opencv
18+
git checkout tags/4.10.0
19+
```
20+
21+
{{% notice Note %}}
22+
You might be able to use a later version. These steps have been tested with the version 4.10.0.
23+
{{% /notice %}}
24+
25+
### Build with MSVC
26+
27+
Here, you will use CMake from the command line. First, Run the following command to run the pre-build configuration.
28+
29+
```bash
30+
mkdir build_msvc
31+
cd build_msvc
32+
33+
cmake `
34+
-S .. `
35+
-B . `
36+
-G "Visual Studio 17 2022" `
37+
-DCMAKE_BUILD_TYPE=Release `
38+
-DBUILD_opencv_world=ON `
39+
-DWITH_ITT=OFF `
40+
-DWITH_OPENCL=OFF `
41+
-DWITH_OPENCLAMDBLAS=OFF `
42+
-DWITH_OPENCLAMDFFT=OFF `
43+
-DWITH_OPENCL_D3D11_NV=OFF `
44+
-DWITH_DIRECTML=OFF `
45+
-DWITH_DIRECTX=OFF `
46+
-DWITH_ADE=OFF `
47+
-DWITH_CAROTENE=OFF
48+
```
49+
50+
The given options specify the following:
51+
- The source code is located one level above the current directory.
52+
- The build will be performed in the current directory.
53+
- The Visual Studio 2022 MSVC compiler will be used as the compiler.
54+
- The built library is generated as a single file that includes all of OpenCV's functionality.
55+
- Disable unnecessary options, assuming processing on Arm CPU.Unnecessary options have been disabled to execute processing on Arm CPUs.
56+
57+
58+
If the configuration is successful, a message similar to the following should be displayed at the end of the execution:
59+
60+
```
61+
-- General configuration for OpenCV 4.10.0 =====================================
62+
-- Version control: 4.10.0
63+
--
64+
-- Platform:
65+
-- Timestamp: 2024-11-06T17:47:31Z
66+
-- Host: Windows 10.0.22631 ARM64
67+
-- CMake: 3.28.1
68+
-- CMake generator: Visual Studio 17 2022
69+
-- CMake build tool: C:/Program Files/Microsoft Visual Studio/2022/Professional/MSBuild/Current/Bin/arm64/MSBuild.exe
70+
-- MSVC: 1941
71+
-- Configuration: Release
72+
--
73+
-- CPU/HW features:
74+
-- Baseline: NEON
75+
-- requested: NEON FP16
76+
-- Dispatched code generation: NEON_DOTPROD NEON_FP16
77+
-- requested: NEON_FP16 NEON_BF16 NEON_DOTPROD
78+
-- NEON_DOTPROD (1 files): + NEON_DOTPROD
79+
-- NEON_FP16 (2 files): + NEON_FP16
80+
--
81+
-- C/C++:
82+
-- Built as dynamic libs?: YES
83+
-- C++ standard: 11
84+
-- C++ Compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.41.34120/bin/Hostarm64/arm64/cl.exe (ver 19.41.34123.0)
85+
[...]
86+
-- C Compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.41.34120/bin/Hostarm64/arm64/cl.exe
87+
[...]
88+
-- Install to: C:/Users/kokmit01/work/opencv/build_msvc/install
89+
-- -----------------------------------------------------------------
90+
--
91+
-- Configuring done (93.6s)
92+
-- Generating done (2.8s)
93+
-- Build files have been written to: C:/Users/kokmit01/work/opencv/build_msvc
94+
```
95+
96+
Now run the following command to build and install:
97+
98+
```bash
99+
cmake --build . --config Release
100+
cmake --build . --target INSTALL --config Release
101+
```
102+
103+
{{% notice Note %}}
104+
The build takes approximately 20 mins on Lenovo X13s
105+
{{% /notice %}}
106+
107+
When the build and the install is complete, confirm the shared library have been created:
108+
109+
```bash { output_lines = "2-12,14-22" }
110+
ls ./install/x64/vc17/bin
111+
Directory: C:\Users\kokmit01\work\opencv\build_msvc\install\x64\vc17\bin
112+
Mode LastWriteTime Length Name
113+
---- ------------- ------ ----
114+
-a---- 07/11/2024 21:56 43008 opencv_annotation.exe
115+
-a---- 07/11/2024 21:56 143872 opencv_interactive-calibration.exe
116+
-a---- 07/11/2024 21:56 41984 opencv_model_diagnostics.exe
117+
-a---- 07/11/2024 22:03 36864 opencv_version.exe
118+
-a---- 07/11/2024 22:03 35328 opencv_version_win32.exe
119+
-a---- 07/11/2024 16:11 26391552 opencv_videoio_ffmpeg4100_64.dll
120+
-a---- 07/11/2024 22:03 56320 opencv_visualisation.exe
121+
-a---- 07/11/2024 21:56 27175936 opencv_world4100.dll
122+
ls ./install/x64/vc17/lib
123+
Directory: C:\Users\kokmit01\work\opencv\build_msvc\install\x64\vc17\lib
124+
Mode LastWriteTime Length Name
125+
---- ------------- ------ ----
126+
-a---- 07/11/2024 16:11 434 OpenCVConfig-version.cmake
127+
-a---- 07/11/2024 16:11 15260 OpenCVConfig.cmake
128+
-a---- 07/11/2024 16:11 972 OpenCVModules-release.cmake
129+
-a---- 07/11/2024 16:11 3879 OpenCVModules.cmake
130+
-a---- 07/11/2024 21:56 2849862 opencv_world4100.lib
131+
```
132+
133+
{{% notice Note %}}
134+
The directory name in the middle is "x64," but there is no need to worry as the generated libraries and executable files will definitely run as ARM64.
135+
{{% /notice %}}
136+
137+
```bash { output_lines = "2" }
138+
./install/x64/vc17/bin/pencv_version.exe
139+
4.10.0
140+
```
141+
142+
## Build OpenCV Applications
143+
144+
145+
Add C:\Users\kokmit01\work\opencv\build\install\x64\vc17\bin to PATH environment variable (for access to dll)
146+
put the dll to the directory with exe file if it doesn't work.
147+
148+
Set include dir/linker path
149+
150+
151+
152+
```cpp
153+
#include <opencv2/opencv.hpp>
154+
#include <iostream>
155+
int main() {
156+
cv::Mat image = cv::Mat::zeros(100, 100, CV_8UC3);
157+
if (image.empty()) {
158+
std::cout << "Failed to create an image!" << std::endl;
159+
return -1;
160+
}
161+
cv::circle(image, cv::Point(50, 50), 30, cv::Scalar(255, 0, 0), -1);
162+
cv::imwrite("test_image.png", image);
163+
cv::waitKey(0);
164+
return 0;
165+
}
166+
```

0 commit comments

Comments
 (0)