I am trying to build OpenCV 4.7 and 4.8 from source code using CMAKE GUI.
If I build without setting OPENCV_EXTRA_MODULES_PATH the CMAKE build and generate succeeds and in Visual Studio I can build and install without any error.
But when I set OPENCV_EXTRA_MODULES_PATH CMAKE build and generate again succeeds but I get the following errors in Visual Studio.
69>cmake_pch.obj : error LNK2019: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits,class std::allocator > …
69>D:\opencv_from_source\python3_10\opencv-4.7.0\build\bin\Release\opencv_xfeatures2d470.dll : fatal error LNK1120: 1 unresolved externals
69>Done building project “opencv_xfeatures2d.vcxproj” – FAILED.
166>cv2.obj : error LNK2019: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits,class std::allocator > …
166>D:\opencv_from_source\python3_10\opencv-4.7.0\build\lib\python3\Release\cv2.cp310-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
166>Done building project “opencv_python3.vcxproj” – FAILED.
When I observe the build directory I see that opencv_xfeatures2d470.dll and cv2.cp310-win_amd64.pyd are not generated by CMAKE.
Can anyone tell what my error is?
I am working on an environment without an internet connection.
When I examine CMAKE configure logs I see that xfeatures2d/vgg tries to download opencv_3rdparty but it becomes unsuccessful.
Should I also include opencv 3rd party packages to CMAKE?
that’s bad. gapi/ade ffmpeg(video support) xfeatures2d and more wont work.
at least you can disable xfeatures2d (& resp. download) with
so it wont get in your way linking the cv2.pyd
what do you mean ? “include” like what ?
Sorry for my poor-quality expression.
I just want to learn if it is possible to involve 3rd party packages to build process like we do for opencv_contrib with OPENCV_EXTRA_MODULES_PATH option?
My main motivation for building opencv from source code is using SURF feature extraction method.
Is there any way for a PC without a net connection to build opencv_contrib with the enabled OPENCV_ENABLE_NONFREE option?
Can I build and generate using CMAKE and build all using Visual studio in another PC and transfer the build folder to my actual PC for installation using Visual Studio?
sounds like an idea.
run cmake once on pc1, let it do the downloads,
then transfer to pc2, and do your VS configuration there
note, that it actually downloads to
opencv/.cache, so you’ll need to transfer that, too.
What about the Python interpreter versions and Visual Studio versions.
I think both PCs must have same python interpreter versions, the same Visual Studio editions?
I will give more feedback. But, I think after I set BÙILD_SHARED_LIBS=OFF Visual Studio build errors about opencv_xfeatures2d470.dll and cv2.cp310-win_amd64.pyd disappeared.
Do you tell that even if the errors are disappeared I can not use features2d?
Here are the steps to build OpenCV with CMAKE and Visual Studio from source code on a machine with Internet connection and transfer build to a machine without Internet connection.
1- Download compatible opencv and opencv-contrib packages and CMAKE.
2- Generate a Conda environment with Python version of destination machine.
3- On CMAKE GUI select opencv folder and a build folder.
4- Using “+Add Entry” option on CMAKE GUI set
PYTHON3_EXECUTABLE, PYTHON3_INCLUDE_DIR, PYTHON3_LIBRARY according to the Conda environment generated
5- Using “+Add Entry” option on CMAKE GUI activate OPENCV_ENABLE_NONFREE
6- Using “+Add Entry” option on CMAKE GUI set OPENCV_EXTRA_MODULES_PATH
7- Click Configure and select the destination machine operating system and Visual Studio version.
8- Configure till all of the parameters that are marked as red disappear.
9- Click Generete.
10- Open .sln file on the build folder using Visual Studio.
11- On Visual Studio select Release.
12- Under CMakeTargets right click ALL_BUILD and select build.
13- If there are no errors right click INSTALL and select build.
14- Under the Python environment find cv2 folder and copy these python bindings to destination machine.
15- Under build folder copy install folder to destination machine
16- Copy python bindings to my_env/Lib/site packages
17- Copy the install folder to a proper destination on destination machine
18- Under cv2 file update the paths in config.py and config-3.10.py files with respect to the folder locations on destination machine
19- Using the Python environment test OpenCV functions