Hi, I would like to use CUDA to speed up my OpenCV python script.
System: win 11
Hardware: laptop with NVIDIA RTX 2000 Ada Generation
I follow this video1 and video2 to setup CUDA. Basically, here are my steps:
- Install CUDA Toolkit, Cmake GUI, Python 3.12, Java, JDK, VS 2022 (video suggested to use VS 2019, but VS 2019 is deprecated , so I used VS 2022). Inside VS 2022, install “Desktop development with C++” (necessary) and “Python development” (unsure if it’s necessary).
- Git clone opencv repo, opencv_contrib repo, create a new empty folder “build”
- Open Cmake GUI, select source code “{path}/opencv” and build binary folder “{path}/build”. Click “Configure” button, select the generator “VS 2022”. Click “OK”.
- Select WITH_CUDA, ENABLE_FAST_MATH, BUILD_opencv_world, provide path for OPENCV_EXTRA_MODULES_PATH “{path}/opencv_contrib/modules” (remember to use /, not ). Then, click “Configure” button again.
- Select CUDA_FAST_MATH. Based on my GPU hardware, select CUDA_ARCH_BIN = 8.6. Change CMAKE_CONFIGURATION_TYPES to “Release”. Click “Configure” button again. Click “Generate” button.
- Open Command Prompt in win 11, type command direcctly: cmake --build "{path}\opencvGPU\build --target INSTALL --config Release
Then, I can see some warnings and a fatal error:
{path}\build\bin\Release\opencv_world4100.dll : fatal error LNK1120: 1 unresolved externals [{path}\build\modules\world\opencv_world.vcxproj]
Please read the complete message below:
C:\Users\StevenWang>cmake --build "C:\Users\StevenWang\opencvGPU\build" --target INSTALL --config Release
(skip some no-error messages here)
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library [C:\Users\Steve
nWang\opencvGPU\build\modules\world\opencv_world.vcxproj]
fast.cpp.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@V
GG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvG
PU\build\modules\world\opencv_world.vcxproj]
logos.cpp.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::cha
r_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@
VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencv
GPU\build\modules\world\opencv_world.vcxproj]
surf.ocl.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@V
GG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvG
PU\build\modules\world\opencv_world.vcxproj]
tbmr.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_tra
its<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@x
features2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\b
uild\modules\world\opencv_world.vcxproj]
vgg.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_trai
ts<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@xf
eatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\bu
ild\modules\world\opencv_world.vcxproj]
xfeatures2d_init.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct s
td::char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefau
ltName@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang
\opencvGPU\build\modules\world\opencv_world.vcxproj]
pct_signatures_sqfd.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struc
t std::char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDe
faultName@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenW
ang\opencvGPU\build\modules\world\opencv_world.vcxproj]
stardetector.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::
char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultNa
me@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\ope
ncvGPU\build\modules\world\opencv_world.vcxproj]
surf.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_tra
its<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@x
features2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\b
uild\modules\world\opencv_world.vcxproj]
surf.cuda.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::cha
r_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@
VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencv
GPU\build\modules\world\opencv_world.vcxproj]
pct_signatures.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std
::char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefault
Name@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\o
pencvGPU\build\modules\world\opencv_world.vcxproj]
grayscale_bitmap.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct s
td::char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefau
ltName@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang
\opencvGPU\build\modules\world\opencv_world.vcxproj]
pct_clusterizer.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct st
d::char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaul
tName@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\
opencvGPU\build\modules\world\opencv_world.vcxproj]
pct_sampler.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::c
har_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultNam
e@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\open
cvGPU\build\modules\world\opencv_world.vcxproj]
harris_lapace_detector.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,st
ruct std::char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?ge
tDefaultName@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\Stev
enWang\opencvGPU\build\modules\world\opencv_world.vcxproj]
latch.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_tr
aits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@
xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\
build\modules\world\opencv_world.vcxproj]
lucid.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_tr
aits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@
xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\
build\modules\world\opencv_world.vcxproj]
msd.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_trai
ts<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@xf
eatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\bu
ild\modules\world\opencv_world.vcxproj]
daisy.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_tr
aits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@
xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\
build\modules\world\opencv_world.vcxproj]
ellipticKeyPoint.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct s
td::char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefau
ltName@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang
\opencvGPU\build\modules\world\opencv_world.vcxproj]
freak.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_tr
aits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@
xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\
build\modules\world\opencv_world.vcxproj]
gms.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_trai
ts<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@xf
eatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\bu
ild\modules\world\opencv_world.vcxproj]
affine_feature2d.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct s
td::char_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefau
ltName@VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang
\opencvGPU\build\modules\world\opencv_world.vcxproj]
beblid.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_t
raits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG
@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU
\build\modules\world\opencv_world.vcxproj]
boostdesc.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::cha
r_traits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@
VGG@xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencv
GPU\build\modules\world\opencv_world.vcxproj]
brief.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_tr
aits<char>,class std::allocator<char> > __cdecl cv::xfeatures2d::VGG::getDefaultName(void)const " (?getDefaultName@VGG@
xfeatures2d@cv@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) [C:\Users\StevenWang\opencvGPU\
build\modules\world\opencv_world.vcxproj]
C:\Users\StevenWang\opencvGPU\build\bin\Release\opencv_world4100.dll : fatal error LNK1120: 1 unresolved externals [C:\
Users\StevenWang\opencvGPU\build\modules\world\opencv_world.vcxproj]
test_intrin128.avx.cpp
opencv_test_core_AVX.vcxproj -> C:\Users\StevenWang\opencvGPU\build\modules\world\opencv_test_core_AVX.dir\Release\op
encv_test_core_AVX.lib
test_intrin128.avx2.cpp
test_intrin256.avx2.cpp
opencv_test_core_AVX2.vcxproj -> C:\Users\StevenWang\opencvGPU\build\modules\world\opencv_test_core_AVX2.dir\Release\
opencv_test_core_AVX2.lib
test_intrin128.avx512_skx.cpp
test_intrin256.avx512_skx.cpp
test_intrin512.avx512_skx.cpp
opencv_test_core_AVX512_SKX.vcxproj -> C:\Users\StevenWang\opencvGPU\build\modules\world\opencv_test_core_AVX512_SKX.
dir\Release\opencv_test_core_AVX512_SKX.lib
test_intrin128.fp16.cpp
opencv_test_core_FP16.vcxproj -> C:\Users\StevenWang\opencvGPU\build\modules\world\opencv_test_core_FP16.dir\Release\
opencv_test_core_FP16.lib
test_intrin128.sse2.cpp
opencv_test_core_SSE2.vcxproj -> C:\Users\StevenWang\opencvGPU\build\modules\world\opencv_test_core_SSE2.dir\Release\
opencv_test_core_SSE2.lib
test_intrin128.sse3.cpp
opencv_test_core_SSE3.vcxproj -> C:\Users\StevenWang\opencvGPU\build\modules\world\opencv_test_core_SSE3.dir\Release\
opencv_test_core_SSE3.lib
test_intrin128.ssse3.cpp
test_intrin128.sse4_1.cpp
opencv_test_core_SSE4_1.vcxproj -> C:\Users\StevenWang\opencvGPU\build\modules\world\opencv_test_core_SSE4_1.dir\Rele
ase\opencv_test_core_SSE4_1.lib
test_intrin128.sse4_2.cpp
opencv_test_core_SSE4_2.vcxproj -> C:\Users\StevenWang\opencvGPU\build\modules\world\opencv_test_core_SSE4_2.dir\Rele
ase\opencv_test_core_SSE4_2.lib
C:\Users\StevenWang>