Starting from today, we are going to start a new series, this series is "C++ of Opencv Beginner to Improvement". This series is about how to use C++ to realize image processing, defect detection, video processing, machine learning, etc. with Opencv. OpenCV is also new to me, and I'm learning it step by step to improve it. This series is based on C++, so to understand the code, C++ must be a little basic.
A brief explanation of what OpenCV is. OpenCV is a cross-platform computer vision library distributed under the BSD license (open source) that runs on Linux, Windows, Android, and Mac OS operating systems. It is lightweight and efficient - consisting of a set of C functions and a handful of C++ classes, while providing interfaces to languages such as Python, Ruby, MATLAB, etc. It implements many general-purpose algorithms for image processing and computer vision.
In the development of computer vision projects, OpenCV as a large number of open source libraries, has a rich library of commonly used image processing functions, written in C/C++, can run on Linux/Windows/Mac and other operating systems, can quickly realize some of the image processing and recognition tasks. introduction, if you want to know more, you can go to the Internet to make up their own brain. It's official website address:/。
Today is the first in this series, so without further ado, let's start getting to know it.
I need to make clarifications in case it is not clear to you, and I have listed the specifics.
Operating system: Windows Professional 10 (64-bit)
Development kit: OpenCV - 4.10.0
Development Tools: Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.8.3
Development language: C++ (VC16)
II. Test source code
Once the environment is configured, how do we know if the configuration was successful, if we have the code to execute it.There are image paths in the code that need to be replaced before execution.
2.1、
1 #include <opencv2/> 2 #include <opencv2/highgui/> 3 #include <opencv2/> 4 5 using namespace cv; 6 7 int main() 8 { 9 Mat dest = imread("D:\\360MoveData\\Users\\Administrator\\Desktop\\TestImage\\", -1); 10 namedWindow("demoWindow", cv::WINDOW_AUTOSIZE); 11 imshow("demoWindow", dest); 12 13 waitKey(0); 14 destroyAllWindows(); 15 return 0; 16 }
III. Configuration process
Configuring the C++ version of Opencv is actually not very difficult, it is mainly divided into three steps, Step 1: Download the necessary components, Step 2: Configure environment variables, Step 3: Configure C++ project properties. After the three steps are completed, you can test it next. Although it is divided into 3 steps, but I am in order to do step by step, not divided into three steps, each step in the breakdown.
3.1. Download OpenCV components from the official website.
Official website address:/releases/
I'm going to put up a picture straight away to give you an immediate feel for it. The latest version is 4.10.0, but of course there are other versions listed on this page, and I'm using the latest one.
3.2. Since my system is the Windows version, I clicked on the [Windows] connection to start the installation program for the Windows version now.
3.3, when opencv-4.10. download is complete, double-click the direct installation can be. My installation directory is the E drive, do not include Chinese characters in the directory.
After the download is complete, we double-click the exe file, decompress the file, I stored in the E disk. I store it on the E drive, as shown in the picture:
Click [Extract] to unzip the file.
After decompression is complete, an opencv directory will be created on the E drive, enter the directory, as shown in the figure:
Go to the E:\opencv\build directory, which is the generated project, as shown:
Under the x64 directory, there is a directory that reads E:\opencv\build\x64\vc16\bin, and this is the address to add to the environment variable. As shown in the figure:
3.4, start configuring environment variables, right-click [this computer], select [Properties], enter the [Settings] window. Click on the right side of the window [Advanced System Settings], as shown:
3.5 Click [Advanced System Settings] to open the [System Properties] window, select the [Advanced] tab, click the [Environment Variables] button below. As shown:
3.6 Click the [Environment Variables] button to open the [Environment Variables] window. As shown:
3.7, in the [Environment Variables] window below the [System Variables] section, find the [Path] configuration item, click the [Edit] button to open the edit window. As shown:
3.8 In the [System Variables] window, select the [Path] item, click the [Edit] button to open the [Edit Environment Variables] window. As shown:
3.9, into the [Edit Environment Variables] window, first click the [New] button, will be at the bottom of the window list, there is a blank line, will be opencv's bin directory, copy in this, click the [OK] button to complete.
3.10. Now, we need to configure some settings for the Visual Studio 2022 C++ project. First, we create an empty C++ project using VS2022. The result is shown in the figure:
3.11, first select the [-001] project, right-click and select [Properties], or click the shortcut key [alter + enter], open the project properties window, as shown:
The ones marked in red are the ones we want to configure. There are two main items: the VC++ catalog, and the input items for the connector.
3.12. Next, we first configure the [VC++ directory] of the [include directory and library directory]. Include directory, the configuration content is: E:\opencv\build\include, library directory: E:\opencv\build\x64\vc16\lib.
Configure the library catalog, the operation is almost the same. Click on the right side of the [library catalog], edit button, open the edit window. As shown in the figure:
Edit the library catalog.
The final result, as shown:
3.13. Configure the [Input] project of the VC++ connector. It is to add the opencv_world4100d.lib file under the library directory: E:\opencv\build\x64\vc16\lib. As shown in the figure:
Click the [Edit] button to open the edit window.
3.14. At this point, we are all configured, you can write code to test.
IV. Summary
This is the first article of using OpenCV in C++, it's very simple, it mainly tells how to configure the environment in order to use OpenCV in C++ environment, I was busy for the first time to configure it, but fortunately, it worked in the end. I'm glad it worked. I'm seeing results, keep up the good work. I'm not forgetting my original intention, keep working hard, do what I like to do, just be happy.