# How to Install OpenCV 5 on Windows and Linux (CMake + MSVC)

> Install OpenCV 5 on Windows or Linux using binaries or a CMake source build with MSVC, contrib modules, C++17 and a simple verification program.

- Canonical URL: https://www.funvisiontutorials.com/blog/install-opencv-5-windows-linux-cmake-msvc/
- Author: Vladimir Kucera
- Published: 2026-07-22
- Updated: 2026-09-10
- Topics: Installing & building OpenCV, Docker & deployment

When OpenCV 5 was finally released in June 2026, I couldn't wait to try it. It’s almost habit with new release. I have been building Opencv 2, 3, 4.x for years, and a major version always makes me little bit nervous, will my pipelines break?

[[Image: Mastering opencv 5 installation]](#)

My first instinct was vcpkg, like always. Bad news: **the OpenCV 5 package isn't in vcpkg yet**. So I went back to the classics.

In this article, I'll show you three ways I got OpenCV 5 running: the official prebuilt Windows package (2 minutes), a full CMake + Visual Studio source build (full control), and Linux from source. Almost all I need nowadays.

## 1\. The Fast Way: Official Prebuilt Windows Package

OpenCV still publishes prebuilt Windows binaries for every release — I just hadn't used them in years. Grab **opencv-5.0.0-windows.exe** from the GitHub releases page ([https://github.com/opencv/opencv/releases#release-5.0.0](#)) or SourceForge.

[[Image: The OpenCV 5.0.0 GitHub release page, with opencv-5.0.0-windows.exe among the seven downloadable assets]](#)

Run it — it's a self-extracting archive, not an installer. I extract to `C:\opencv5`. Inside you get headers, libs and DLLs built with a recent MSVC.

Then point your project at it. My minimal CMakeLists.txt:

```cmake
cmake_minimum_required(VERSION 3.22)
project(cv5test)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(OPENCV_DIR "C:/projects/opencv5/opencv-5.x/build/install")
list(APPEND CMAKE_PREFIX_PATH "${OPENCV_DIR}")
find_package(OpenCV 5.0.0 REQUIRED)

add_executable(cv5test main.cpp)
target_link_libraries(cv5test PRIVATE ${OpenCV_LIBS})

target_include_directories(${PROJECT_NAME} PRIVATE
    ${OpenCV_INCLUDE_DIRS}
)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
    # Copy OpenCV runtime DLLs
    COMMAND ${CMAKE_COMMAND} -E copy_directory_if_newer
        "${OPENCV_DIR}/x64/vc18/bin"   # Note: VS2026 uses the vc18 designation
        $<TARGET_FILE_DIR:${PROJECT_NAME}>

    COMMENT "Verifying and copying required OpenCV and FFmpeg runtime DLLs..."
)
```

Two things to remember:

-   **Add the bin folder to PATH** → otherwise the exe compiles fine and then dies at startup, missing  DLLs. I have in cmake the copy of DLLs next to executable, to be able to build multiple OpenCV versions on one system. add\_custom\_command(copy dll to my project from installation dir)

-   Configure and build commands (execute in directory where main.cpp and CMakeLists.txt are located)

cmake -S . -B build -G "Visual Studio 18 2026" -A x64
cmake --build build --config Release --parallel

-   **No contrib modules** → the official prebuilt package ships default parameters only. Need contrib? Build from source (next section)

## 2\. The Full Control Way: CMake + Visual Studio from Source

This is what I actually did, because I wanted contrib modules and my own flags:

```bash
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
cd opencv && git checkout 5.x

I created build_test folder

Configure with contrib
cmake -S opencv -B build_test -G "Visual Studio 18 2026" -A x64 ^
  -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib/modules ^
  -DBUILD_opencv_world=ON ^
  -DCMAKE_INSTALL_PREFIX=C:/opencv5-custom

Without contrib
cmake -B build_test -G "Visual Studio 18 2026" -A x64 -DBUILD_opencv_world=ON
 -DCMAKE_INSTALL_PREFIX=C:/projects/opencv5/opencv-5.x/test_install

Screen expected after configuration
Than build
cmake --build build_test --config Release --target INSTALL -j8
```

What clicked for me after years of cmake-gui clicking: the whole configuration is just these flags. **BUILD\_opencv\_world=ON** merges everything into one DLL — one library to link, my favorite convenience for tutorials and prototypes.

Prefer clicking? cmake-gui works exactly the same: Browse Source → Browse Build → Configure (pick Visual Studio 17 2022,Visual Studio 18 2026) → set the same options → Generate → open the .sln and build the INSTALL target in Release.

The build takes anywhere from 15 minutes to over an hour depending on your machine. Go make coffee or two.

## 3\. The Trap I Fell Into: MinGW and the DNN Module

I also tried a MinGW-w64 build on one machine — and the **DNN module failed to compile**. The reason: OpenCV 5's new DNN engine pulled in MLAS for CPU acceleration, and it doesn't build cleanly under MinGW yet.

The workaround is to disable the module:

```bash
cmake ... -DBUILD_opencv_dnn=OFF
```

But be honest with yourself: the new DNN engine is half the reason to upgrade to OpenCV 5. My advice — **use MSVC on Windows** until the toolchain settles. Keep an eye on the OpenCV GitHub for a proper fix.

## 4\. Linux: Still the Smoothest

```bash
git clone https://github.com/opencv/opencv.git
cd opencv && git checkout 5.x
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j8
sudo cmake --install build
```

One thing I learned the hard way on every platform: **C++17 is now the minimum standard**. My old projects with `-std=c++11` refused to compile against the new headers. One line fixes it:

```cmake
set(CMAKE_CXX_STANDARD 17)
```

## 5\. Verifying the Build

My first program with every new OpenCV version is always the same:

```cpp
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;

int main() {
    std::cout << "OpenCV version: " << CV_VERSION << std::endl;

    Mat canvas = Mat::zeros(200, 500, CV_8UC3);
    putText(canvas, "OpenCV 5 is alive!", Point(40, 110),
            FONT_HERSHEY_SIMPLEX, 1.0, Scalar(60, 200, 60), 2);
    imshow("check", canvas);
    waitKey(0);
    return 0;
}

Use same
```

CMakeLists.txt and commands like in chapter 1.

```bash
cmake -S . -B build -G "Visual Studio 18 2026" -A x64
cmake --build build --config Release --parallel
```

If CV\_VERSION prints 5.x — you are ready.

## 6\. What Actually Changed in 5.0 (The Short Version)

I read the full release notes so you don't have to:

-   **New DNN engine** → graph-based, ONNX operator coverage jumped from ~22% to 80%+. Modern models finally load.
-   **New data types** → FP16, BF16, bool, 64-bit integers. Mat can now be 0-D or 1-D.
-   **USAC** → the default robust estimator for homography, PnP, fundamental matrix. Better than classic RANSAC on noisy data.
-   **calib3d is gone** → split into **geometry**, **calib** and **stereo** modules. Old `#include <opencv2/calib3d.hpp>` code needs the migration guide.
-   **Legacy C API removed** → if you still have `cvLoadImage` somewhere, it's time.

## 7\. My Key Takeaways

-   vcpkg doesn't have OpenCV 5 yet — the prebuilt .exe from GitHub releases is the new fast path
-   Prebuilt = 2 minutes but no contrib; source build = full control + opencv\_world convenience
-   MinGW + the new DNN module don't mix yet — use MSVC on Windows
-   C++17 minimum: update CMake before anything else
-   Check the migration guide for the calib3d split

## Conclusion

Losing vcpkg for a release cycle turned out to be a blessing — it forced me to relearn how simple the official packages and a clean CMake build actually are. And the DNN engine — that changed what I can build with OpenCV alone.

In the next article, I'll go back to fundamentals: reading, displaying and saving images and video — with the memory details that took me too long to learn.

**my tip:**

Need help to install, compile opencv C++ program? Use Agents in Antigravity, Cursor, Gemini CLI, Claude to do this for you.
