Visual Stdio2022+Opencv4.8.0+Opencv-contrib+Cmake3.27.1

Visual Studio has been installed by default. I only installed opencv before and found that some functions cannot be implemented and need to rely on opencv-contrib, so I will record it here.

1. Install opencv, opencv-contrib, Cmake

opencv installation link: Releases - OpenCV https://opencv.org/releases/

opencv-contrib installation link:  Tags · opencv/opencv_contrib · GitHub https://github.com/opencv/opencv_contrib/tags

 Cmake installation link: Download | CMake https://cmake.org/download/

 The Cmake I installed is the .msi file of version 3.27.1. The operation is relatively simple, as shown in the figure:

After installation, unzip:

2. Cmake compilation

 1. Double-click cmake-3.27.1-windows-x86_64 and click Next.

 After the installation is complete, open cmake. Sometimes it will look like the picture below. In this case, place the mouse cursor between the blank area and the sentence "Where to build the binaries", and the mouse will become able to be pulled up and down. Slider, just hold down the left mouse button to open it.

 1 is the downloaded opencv file path, that is, the source code path; 2 is the path where it is stored after compilation. This path is very important and will be used later.

 After filling in the path, click Configure, and a box will pop up. The first selection box will usually be detected and generally does not need to be modified. Select x64 in the second selection box. Click Finish and wait for a while. An error will usually be reported during this process.

 BUILD_opencv_world must be checked, OPENCV_EXTRA_MODULES_PATH: fill in the path of opencv_contrib/modules, mine is in D:/opencv_contrib-4.8.0/modules.

  2. Error report 1: I had an error report before, but the problem was solved. When I uninstalled it again and tried it again, the error message disappeared and there was no way to record it. At that time, I found the CMakeDownloadLog.txt file under the compiled storage path D:\opencv\opencv-4.8.0-Build. Follow his prompts to re-download the unsuccessful files and replace the unsuccessful files. Refer to It's this blog. Visual Studio 2022 configures OpenCV455+CMake (Win11)_opencv cmake vs2022_qq_44658189's blog-CSDN blog https://blog.csdn.net/qq_44658189/article/details/125030551 Error report 2: Unable to download ADE, I found a blog below comment, the solution was solved according to this netizen's method. He said that he found the path D:\opencv\opencv\sources\modules\gapi\cmake\, opened the DownloadADE.cmake file, found lines 20~22, and modified it to his own actual path. My ade-release_0.1 is downloaded from GitHub at this URL - opencv/ade at release_0.1

Warning 1: The warning I encountered is as shown in the picture. It said that there is a problem in line 649 of the CmakeLists.txt file. I searched online first and it said that CMP0148 has been deprecated after cmake3.12 version. , and then I found the CMakeLists.txt file under the opencv source code path D:\opencv\opencv\sources and opened it and found this line.

 The related ones were logged out. The warning is gone.

 Configuring is successful and no red color appears, indicating success. Click Generate to proceed to the next step. If the following situation occurs and there is no explosion of popularity, it means success.

 3.Visual Studio compilation

Find the OpenCV.sln file under the cmake compiled file and open it with Visual Studio. Note that you must run it as an administrator. You can open visual studio as an administrator first, and then find the path to open it from vs.

 Right click on the solution -> Generate solution, this process is a bit long.

 After completion, it will be as shown in the picture.

 Find CMakeTargets->INSTALL right-click in the right column and find only for projects->Build INSTALL only (B) click.

 After completion, find the install file in the cmake generation path and open it, as shown in the figure.

 Copy the following path to the computer Path environment variable. If you already have the opencv environment variable before, remember to delete it.

 4. Test

Open the Visual Studio software, rebuild a project, or open the project you need to use opencv. Click Project->Properties to find the include directory and library directory in the VC++ directory.

 Add: D:\opencv\opencv-4.8.0-Build\install\include and D:\opencv\opencv-4.8.0-Build\install\include\opencv2 to the include directory; add D:\ opencv\opencv-4.8.0-Build\install\x64\vc17\lib.

 Find additional dependencies in the input options in the linker, add D:\opencv\opencv-4.8.0-Build\install\x64\vc17\lib\opencv_world480d.lib (Debug version, release without d), if in Cmake When compiling, BUILD_opencv_world is not checked, and there is no opencv_world480d.lib. I think some bloggers say that if you don't select it, you need to put in all the items with d in it. I don't know if that works.

 When finished, click OK to complete the configuration. You can run the code for testing. I ran a video of yolov detecting horses as shown in the picture.

Additional explanation: When I did image stitching later, I used the SURF algorithm. I found that the program did not report an error, but it could not run. However, when I ran the SIFT algorithm, it worked. I found some solutions on the Internet, and it was said that the opencv version was too high. , there is no copyright of SURF, so I need to uninstall OPENCV and opencv_contrib and install a lower version, but I finally got it after stumbling all the way. I don’t want to give up. Later, I saw in a blog that I need to reopen cmake and find the OPENCV_ENABLE_NONFREE item to check. , re-Configure->Generate, and then re- compile with Visual Studio 3. Since the problems encountered before were perfectly solved, it went smoothly and did not waste much time. After that SURF is ready to use.

Guess you like

Origin blog.csdn.net/weixin_50847463/article/details/132208621