Skip to content

Commit 18a11d2

Browse files
committed
add how to build app and update description
1 parent db80610 commit 18a11d2

File tree

14 files changed

+199
-88
lines changed

14 files changed

+199
-88
lines changed

content/learning-paths/laptops-and-desktops/win-opencv/1-opencv-compilers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: OpenCV and Compilers
2+
title: OpenCV and Compilers for Windows on Arm
33
weight: 2
44

55
### FIXED, DO NOT MODIFY
@@ -30,13 +30,13 @@ When building applications for Windows on Arm, both MSVC (Microsoft Visual C++)
3030

3131
* __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.
3232

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.
33+
* __Clang__: An open-source compiler that is part of the LLVM project. It’s known for its modern design and cross-platform capabilities.
3434

3535
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.
3636

3737
## Before you begin
3838

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.
39+
Any Windows on Arm machine which has the required tools installed can be used for this Learning Path. You will learn the build methods using both MSVC and Clang.
4040

4141
Please install the following tools required for both methods.
4242

@@ -76,4 +76,4 @@ The instructions were tested with version 1.11.1
7676

7777
You use the LLVM Clang and the Ninja generator to build. Set PATH to the paths to your LLVM and Ninja install.
7878

79-
You now have the required development tools installed.Please proceed to the page for the compiler you want to build with.
79+
You now have the required development tools installed. Please proceed to the page for the compiler you want to build with.

content/learning-paths/laptops-and-desktops/win-opencv/2-1-build-msvc.md

Lines changed: 90 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ git checkout tags/4.10.0
2222
You might be able to use a later version. These steps have been tested with the version 4.10.0.
2323
{{% /notice %}}
2424

25-
### Build with MSVC
25+
### Pre-build configuration
2626

27-
Here, you will use CMake from the command line. First, Run the following command to run the pre-build configuration.
27+
Here, you will use CMake from the command line. First, run the following command to run the pre-build configuration.
2828

2929
```bash
3030
mkdir build_msvc
@@ -52,8 +52,9 @@ The given options specify the following:
5252
- The build will be performed in the current directory.
5353
- The Visual Studio 2022 MSVC compiler will be used as the compiler.
5454
- 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.
55+
- Unnecessary options have been disabled, assuming processing on Arm CPUs.
5656

57+
 
5758

5859
If the configuration is successful, a message similar to the following should be displayed at the end of the execution:
5960

@@ -62,13 +63,13 @@ If the configuration is successful, a message similar to the following should be
6263
-- Version control: 4.10.0
6364
--
6465
-- Platform:
65-
-- Timestamp: 2024-11-06T17:47:31Z
66+
-- Timestamp: 2024-11-08T08:50:24Z
6667
-- Host: Windows 10.0.22631 ARM64
6768
-- CMake: 3.28.1
6869
-- CMake generator: Visual Studio 17 2022
6970
-- CMake build tool: C:/Program Files/Microsoft Visual Studio/2022/Professional/MSBuild/Current/Bin/arm64/MSBuild.exe
7071
-- MSVC: 1941
71-
-- Configuration: Release
72+
-- Configuration: Debug Release
7273
--
7374
-- CPU/HW features:
7475
-- Baseline: NEON
@@ -88,11 +89,13 @@ If the configuration is successful, a message similar to the following should be
8889
-- Install to: C:/Users/kokmit01/work/opencv/build_msvc/install
8990
-- -----------------------------------------------------------------
9091
--
91-
-- Configuring done (93.6s)
92+
-- Configuring done (97.5s)
9293
-- Generating done (2.8s)
9394
-- Build files have been written to: C:/Users/kokmit01/work/opencv/build_msvc
9495
```
9596

97+
### Build and install
98+
9699
Now run the following command to build and install:
97100

98101
```bash
@@ -101,53 +104,72 @@ cmake --build . --target INSTALL --config Release
101104
```
102105

103106
{{% notice Note %}}
104-
The build takes approximately 20 mins on Lenovo X13s
107+
The build takes approximately 25 mins on Lenovo X13s
105108
{{% /notice %}}
106109

110+
 
111+
107112
When the build and the install is complete, confirm the shared library have been created:
108113

109-
```bash { output_lines = "2-12,14-22" }
114+
```bash { output_lines = "2-12,15-22" }
110115
ls ./install/x64/vc17/bin
111116
Directory: C:\Users\kokmit01\work\opencv\build_msvc\install\x64\vc17\bin
112117
Mode LastWriteTime Length Name
113118
---- ------------- ------ ----
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
119+
-a---- 08/11/2024 09:03 43008 opencv_annotation.exe
120+
-a---- 08/11/2024 09:03 143872 opencv_interactive-calibration.exe
121+
-a---- 08/11/2024 09:03 41984 opencv_model_diagnostics.exe
122+
-a---- 08/11/2024 09:12 36864 opencv_version.exe
123+
-a---- 08/11/2024 09:12 35328 opencv_version_win32.exe
124+
-a---- 08/11/2024 08:50 26391552 opencv_videoio_ffmpeg4100_64.dll
125+
-a---- 08/11/2024 09:12 56320 opencv_visualisation.exe
126+
-a---- 08/11/2024 09:03 27179008 opencv_world4100.dll
127+
122128
ls ./install/x64/vc17/lib
123129
Directory: C:\Users\kokmit01\work\opencv\build_msvc\install\x64\vc17\lib
124130
Mode LastWriteTime Length Name
125131
---- ------------- ------ ----
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
132+
-a---- 08/11/2024 08:50 434 OpenCVConfig-version.cmake
133+
-a---- 08/11/2024 08:50 15260 OpenCVConfig.cmake
134+
-a---- 08/11/2024 08:50 972 OpenCVModules-release.cmake
135+
-a---- 08/11/2024 08:50 3879 OpenCVModules.cmake
136+
-a---- 08/11/2024 09:02 2849862 opencv_world4100.lib
131137
```
132138

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 %}}
139+
 
140+
141+
`opencv_world<version>.lib/dll` will be the library used by your application. Once the library files are correctly generated, run the following command to ensure there are no errors.
136142

137143
```bash { output_lines = "2" }
138-
./install/x64/vc17/bin/pencv_version.exe
144+
./install/x64/vc17/bin/opencv_version.exe
139145
4.10.0
140146
```
141147

148+
{{% notice Note %}}
149+
The genereated directory name contains "x64," but there is no need to worry as the libraries and executable files will definitely run as ARM64.
150+
{{% /notice %}}
151+
152+
&nbsp;
153+
142154
## Build OpenCV Applications
143155

156+
Once the OpenCV library has been successfully built, the next step is to link it to a simple application and try using it.
157+
158+
### Create a new project in Visual Studio
159+
160+
First, create a new project in Visual Studio. Launch Visual Studio, click `Create a new project` on the initial screen, then select `Empty Project` and click `Next`. On the next screen, set the `Project name` and `Location`. You can choose any name and location, but for this example, we named the project `TestOpenCV`, as shown below. Then click `Create` to generate the new project.
161+
162+
![MSVC project](msvc_project.png "Create a new project")
163+
164+
### Adding a source code
144165

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.
166+
In `Solution Explorer`, right-click the `Source Files` folder, select `Add`, and then `New Item...`. Create a file named `test_opencv.cpp`.
147167

148-
Set include dir/linker path
168+
![MSVC add file](msvc_add_file.png "Add a source file")
149169

170+
&nbsp;
150171

172+
Once the file is created, it will open in the editor. Copy and paste the following program into it and save the file.
151173

152174
```cpp
153175
#include <opencv2/opencv.hpp>
@@ -163,4 +185,43 @@ int main() {
163185
cv::waitKey(0);
164186
return 0;
165187
}
166-
```
188+
```
189+
190+
This program is a simple example that uses OpenCV's functionality to create a 100x100 black image, draw a blue circle on it, and save it as a file.
191+
192+
### Configure build settings
193+
194+
Next, select the `Configuration` dropdown menu in the center of the screen and change it from `Debug` to `Release`. At this stage, your screen should look like the example shown below.
195+
196+
![MSVC screenshot](msvc_screen.png "MSVC screenshot")
197+
198+
&nbsp;
199+
200+
Now, set up the compile and link settings. Select `Project` from the top menu and click on `TestOpenCV properties`. Edit `Include directories`, `Library directories`, and `Additional dependencies` as shown in the images below, and then click OK.
201+
202+
![MSVC include dir](msvc_include_dir.png "Include directories: Specify the directory containing the OpenCV header files.")
203+
204+
&nbsp;
205+
206+
![MSVC link dir](msvc_link_dir.png "Library directories: Specify the directory where the libraries for linking are located.")
207+
208+
&nbsp;
209+
210+
![MSVC link lib](msvc_link_lib.png "Additional dependencies: Specify the names of the libraries to link")
211+
212+
&nbsp;
213+
214+
Finally, ensure that the directory containing the dynamic libraries (DLLs) is added to the `PATH` environment variable. Set this in the Windows system settings. After setting the environment variable, restart Visual Studio to apply the changes.
215+
216+
![path setting](set_path.png "Set the DLL dir to the PATH environment variable")
217+
218+
### Run the build
219+
220+
Once these steps are complete, you're ready to build. From the top menu, select `Debug` and click `Start Without Debugging` or press `Ctrl` + `F5`.
221+
222+
If a console window appears showing that the program exited with code 0 and `test_image.png` is generated in the top-level directory of your Visual Studio project, you have succeeded. When you open the image file, it should look like the example shown below.
223+
224+
![test_image pic](test_image.png "test_image.png")
225+
226+
Congratulations! You are now ready to create your own OpenCV applications.
227+

0 commit comments

Comments
 (0)