Windows 11 installation of OpenCV and its learning route

Windows 11 Download and install OpenCV

First download the library file, as shown in the figure below, enter the OpenCV official website , select Library->Releases, and enter the Release library file package download page.

 Select the Windows system file to download, and the download will automatically start after clicking the selection.

In this case, OpenCV-4.8.0 version is selected. The downloaded file is named opencv-4.8.0-windows.exe. Double-click the file to decompress it. 

You can also right-click the file and select "Extract to current folder", which will extract the folder opencv under the current path, which contains two subfolders:

--build, stores compiled binary library files;

--sources, stores the source code of the current version.

Enter the build folder. There are six folders under the path:

--bin, stores third-party library dependency files;

--etc, store resource files;

--include, store header files;

--java, stores Windows system Java library files;

--python, stores the Python language installation files for Windows systems;

--x64 stores Windows C++ library files, vc16 versions.

 For Visual Studio 2022, you can choose the library file corresponding to the latest version of the vc16 compiler. The vc16 path contains two folders: bin (storing dynamic library files) and lib (storing static library files). The most important OpenCV tool library call The three files are: header file (stored in the include folder), dynamic library (opencv_world480.dll or opencv_world480d.dll) and static library (opencv_world480.lib or opencv_world480d.lib).

Visual Studio 2022 + OpenCV Quick Start 

Choose to open Visual Studio 2022 and create a new project. When creating a project, you can directly choose to create a "console application". The created project has the main program and outputs "Hello World" by default.

Configure a new project, set the project name and project location, the solution name can use the default, which is the same as the project name.

 

In order to use OpenCV, you need to configure the OpenCV library reference in the project. The environment configuration needs to configure three aspects: including directory, library directory and linker dependencies.

Configure additional dependencies in "Linker-Input-Additional Dependencies", that is, the name of the static library file.

After selecting "Apply" and "OK", the configuration is completed and the test code is written to test the use of the OpenCV library.

Display: Read an image and display the image. 

// OpenCV_Demo.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "opencv2/opencv.hpp"

int main()
{
    cv::Mat img = cv::imread("E:\\images\\1.png", 1);         //图像读取
    cv::imshow("测试图像显示", img);                //图像显示
    cv::waitKey(0);                                 //等待读者操作
    cv::destroyWindow("测试图像显示");              //窗口对象销毁
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

 

Problems encountered

There are no errors in compilation. Press F5 to run the project. The following screenshot error message is prompted.

The error is called a "runtime error". A common cause of runtime errors is that the dynamic library file cannot be found or does not match. There are two solutions to this problem:

Solution:

 The first one: (Personally recommended) Configure the dynamic library path into the environment variable. Readers can select "Computer->Properties->Advanced System Settings->Environment Variables", find the Path variable, and configure the opencv/build/x64/vc16/bin path in the OpenCV file package to the environment variable, so that it can be Find the path to the dynamic library.

Second method: Copy the dynamic library to the path of the generated executable file.

The above two methods are to enable the executable file OpenCVdemo.exe to find the OpenCV dynamic library file in the search path. The current path and environment variables are both search paths when linking executable files in Windows systems. 

OpenCV learning roadmap 

  • core module

OpenCV's core module is the core module of the entire library. It provides a large number of functions and classes to support almost all operations in the fields of image processing, computer vision, and machine learning. The main functions of this module include:

  1. Array structure: The most important data structure in the core module is Mat, which is a multi-dimensional array used to store images and other data. In addition, it also defines some vector objects, such as Point, Size and Rect.

  2. Mathematical operations and matrix processing: The core module provides a large number of mathematical functions and linear algebra tools, such as matrix operations, eigenvalue decomposition, SVD decomposition, linear equations solution, etc.

  • imgcodecs module

OpenCV's imgcodecs module is a module for loading and saving images. It provides a wide range of image codecs, including JPEG, PNG, BMP, GIF, TIFF and other formats. At the same time, it supports the use of multiple compression methods to store and read image data, such as lossless compression, area compression, etc.

  • Imgproc module

OpenCV's imgproc module is one of the most important modules in the field of computer vision, providing rich functions and powerful performance in image processing. This module mainly provides the following functions:

  1. Image transformation: including multiple transformation methods such as scaling, rotation, affine and perspective transformation, and also provides epipolar constraint transformation functions.

  2. Image filtering: Provides various types of image filters, such as Gaussian filters, median filters, bilateral filters, etc., as well as morphological filters, such as erosion, expansion, opening operations, and closing operations, for processing images. Noise and misperception in situations.

  3. Image segmentation: including methods such as threshold segmentation, adaptive threshold segmentation, region growing, and watershed segmentation. Common application areas are target detection and recognition.

  4. Shape analysis: The core module uses center of gravity, contour analysis, convex hull, graphic approximation and other technologies to perform feature analysis methods on two-dimensional or three-dimensional objects, such as detecting circles and straight lines in images, measuring object size and shape, etc.

  • highgui module

OpenCV's highgui module is a module specially used for window display and event processing. This module provides functions and tools that can be used to create GUI interfaces and interact with images or videos. The following are the main functions of the highgui module:

  1. Window management: Provides functions that can be used to create, name, move, reset, and close windows. Common windows include original image windows, mouse interaction windows, control bar windows, etc.

  2. Mouse and keyboard event response: By registering callback functions, users can quickly define events such as mouse clicks and key presses in the window. This feature supports interactive program development.

 

  • videoio module

OpenCV's videoio module provides a series of classes and functions for video input and output. Its main functions include:

Video capture: This module provides the VideoCapture class, which can open a local camera or read a video file, and can read video frames and process them.

Stream compression and decoding: The videoio module provides two classes, VideoWriter and VideoCapture, which can not only encode video frames into encoder calls of specified formats, but also cooperate with the VideoCapture class to decode video frames. Common video codecs include MPEG, H.264, VP8/VP9, etc.

Video output: The video can be stored in a local file through the VideoWriter class and transmitted using the corresponding codec to replace simple interface methods such as FileStorage.

  • video module

OpenCV's video module provides video analysis functions, mainly including motion estimation, background separation, object tracking and other video processing related content.

  • photo module

OpenCV's photo module provides image repair and image denoising related content.

 

  • feature2d module

OpenCV's feature2d module is a module used for image feature extraction and description, providing a variety of key point detection and feature description algorithms.

Common key point detection algorithms include Harris corner point detection, Shi-Tomasi corner point detection, SIFT key point detection, SURF key point detection, etc.; feature description algorithms include SIFT descriptor, SURF descriptor, ORB descriptor, etc.

  •  calib3d module

OpenCV's calib3d module is a module used for camera calibration and three-dimensional reconstruction. It provides a variety of camera calibration and attitude estimation algorithms.

Common camera calibration algorithms include Zhang's method, Tsai's method, OpenCV's own calibration method based on checkerboards and dots, etc. By processing multiple images captured by the calibration board, the camera internal parameter matrix, distortion parameters and other information can be obtained . The attitude estimation algorithm can obtain the three-dimensional position and attitude information of the object from multiple perspectives captured by the camera, including PnP (Perspective-n-Point) problem solving, stereo matching solution, etc.

In addition, the calib3d module also provides functions such as stereo camera calibration, binocular matching, and triangulation, as well as tools for converting pinhole camera models into fisheye camera models.

 

  • objdetect module

OpenCV's objdetect module is a module used for target detection and provides a variety of target detection algorithms and training tools.

Common target detection algorithms include Haar feature classifier (Cascade Classifier), HOG+SVM, etc. The Haar feature classifier is a classifier based on the Adaboost algorithm, which is widely used and easy to understand; while the HOG+SVM is a method based on the Histogram of Oriented Gradients and SVM, which can achieve better target detection results in complex backgrounds.

  • ml module

OpenCV's ml module is a module for machine learning. It provides a variety of classic machine learning algorithms and processes, including classification, regression, clustering, dimensionality reduction and other tasks.

Common machine learning algorithms include KNN, SVM, Decision Tree, Random Forest, etc. These algorithms obtain a model by training sample data, and then use the model to predict or classify new input data.

In addition to providing various machine learning algorithms, the ml module also provides tools such as Feature Selection and Cross-validation, which can help data scientists better build and evaluate machine learning models.

 

  • dnn module

OpenCV's dnn module is a deep learning module that provides tools and algorithms for deep neural networks (DNN), allowing users to use trained neural network models for image and video analysis.

The dnn module supports various common deep learning frameworks, such as Caffe, TensorFlow, MXNet, etc., and provides some pre-trained deep learning models, such as SSD, YOLO, MobileNet, and ResNet. In OpenCV, users can build DNN models and load pre-trained weight files to achieve tasks such as target detection, face recognition, and semantic segmentation.

In addition to loading the pre-trained model, the dnn module also provides some tool functions, such as the BlobFromImage function, which can convert images into blob objects input by the neural network; it also provides some optimization algorithms, such as bounding box regression and non-maximum suppression ( NMS) algorithm to improve the accuracy of target detection.

 OpenCV reference

OpenCV official documentation

Guess you like

Origin blog.csdn.net/zhouzhiwengang/article/details/132831067