Win11+Opencv 4.11.0+Cuda12.8+Cudnn 9.8+freetype 2.13.3+harfbuzz 11.1.0+eigen 3.4.0 支持中文编译opencv
1. 下载freetype
2. 下载harfbuzz
3. 下载opencv-4.11.0 和 opencv_contrib-4.11.0
4. 下载cudnn-windows-x86_64-9.8.0.87_cuda12-archive
5. 下载TensorRT-10.8.0.43.Windows.win10.cuda-12.8.zip
4. 编译freetype 系统变量添加变量FREETYPE_DIR,目录为C:/Program Files (x86)/freetype
5. 编译harfbuzz 初次Configure后,钩选HB_HAVE_FREETYE,再次Configure. 系统变量添加变量HARFBUZZ_DIR,目录为C:/Program Files (x86)/harfbuzz
修改modules/freetype/CMakeLists.txt
替换如下内容
set(the_description "FreeType module. It enables to draw strings with outlines and mono-bitmaps/gray-bitmaps.") find_package(Freetype REQUIRED) # find_package(HarfBuzz) is not included in cmake set(HARFBUZZ_DIR "$ENV{HARFBUZZ_DIR}" CACHE PATH "HarfBuzz directory") find_path(HARFBUZZ_INCLUDE_DIRS NAMES hb-ft.h PATH_SUFFIXES harfbuzz HINTS ${HARFBUZZ_DIR}/include) find_library(HARFBUZZ_LIBRARIES NAMES harfbuzz HINTS ${HARFBUZZ_DIR}/lib) find_package_handle_standard_args(HARFBUZZ DEFAULT_MSG HARFBUZZ_LIBRARIES HARFBUZZ_INCLUDE_DIRS) if(NOT FREETYPE_FOUND) message(STATUS "freetype2: NO") else() message(STATUS "freetype2: YES") endif() if(NOT HARFBUZZ_FOUND) message(STATUS "harfbuzz: NO") else() message(STATUS "harfbuzz: YES") endif() if(FREETYPE_FOUND AND HARFBUZZ_FOUND) ocv_define_module(freetype opencv_core opencv_imgproc PRIVATE_REQUIRED ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES} WRAP python) ocv_include_directories(${FREETYPE_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS}) else() ocv_module_disable(freetype) endif()
6. 编译opencv 4.11.0
需要联网下载文件
a) ippicv
https://raw.githubusercontent.com/opencv/opencv_3rdparty/7f55c0c26be418d494615afca15218566775c725/ippicv/ippicv_2021.12.0_win_intel64_20240425_general.zip
b) opencv_videoio_ffmpeg.dll
https://raw.githubusercontent.com/opencv/opencv_3rdparty/d63d7c154c57242bf2283be61166be2bd30ec47e/ffmpeg/opencv_videoio_ffmpeg.dll
c) opencv_videoio_ffmpeg_64.dll
https://raw.githubusercontent.com/opencv/opencv_3rdparty/d63d7c154c57242bf2283be61166be2bd30ec47e/ffmpeg/opencv_videoio_ffmpeg_64.dll
关键编译选项
建议勾选:
a. OPENCV_DNN_CUDA dnn模块使用cuda加速 需要配置CUDNN_LIBRARY 和 CUDNN_INCLUDE_DIR的路径
b. WITH_EIGEN 把EIGEN 编译进去, 需要额外的eigen库
c. WITH_CUDA 启用cuda加速,必选
d. WITH_CUDNN 启用cudnn 加速,必选
e. BUIlD_opencv_world 打包成一个world文件.
f. CUDA_FAST_MAT 和 ENABLE_FAST_MATH Make use of fast math library.
g. 配置opencv_contrib路径; OPENCV_EXTRA_MODULES_PATH=E:\HW-Traffic\5_Source\Source\opencv_contrib-4.11.0\modules
i. 配置freetype


最后freetype 再To be built里面就行
j. 勾选OPENCV_ENABLE_NONFREE
k. 启用Nvidia Video Codec SDK 编解码: WITH_NVCUVENC WITH_NVCUVID


ARCH对应表可以通过网址查询:
https://developer.nvidia.com/cuda-gpus
修改 ARCH:
5.0;5.2;6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0
7.5;8.6;8.9;12.0
常用的几款列举:
NVIDIA T4 Quadro RTX Geforce RTX 20 7.5
NVIDIA A10 RTX Geforce RTX 30 8.6
Geforce RTX 40 NVIDIA L40 8.9
Geforce RTX 50 12.0
建议取消勾选:
a. OPENCV_GENERATE_SETUPVARS 若build目录是不是子目录,会有警告
b. BUILD_TESTS 编译测试工程
c. BUILD_opencv_ts 编译测试模块
d. BUILD_EXAMPLES 编译例子工程
e. BUILD_JAVA java工程
部分报错:

2. harfbuzz报错的话
18>harfbuzz.lib(harfbuzz.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“0”不匹配值“2”(algorithm.obj 中)
18>harfbuzz.lib(harfbuzz.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(algorithm.obj 中)
debug 和release 不匹配.
OpenCV modules:
To be built: alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape signal stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
Disabled: java_bindings_generator python_bindings_generator python_tests ts
Disabled by dependency: -
Unavailable: cannops cvv fastcv hdf java julia matlab ovis python2 python3 sfm viz
Applications: apps
Documentation: NO
Non-free algorithms: YES
Windows RT support: NO
GUI:
Win32 UI: YES
VTK support: NO
Media I/O:
ZLib: build (ver 1.3.1)
JPEG: build-libjpeg-turbo (ver 3.0.3-70)
SIMD Support Request: YES
SIMD Support: NO
WEBP: build (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
AVIF: NO
PNG: build (ver 1.6.43)
SIMD Support Request: YES
SIMD Support: YES (Intel SSE)
TIFF: build (ver 42 - 4.6.0)
JPEG 2000: build (ver 2.5.0)
OpenEXR: build (ver 2.3.0)
GIF: NO
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES
Video I/O:
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES
Media Foundation: YES
DXVA: YES
Parallel framework: Concurrency
Trace: YES (with Intel ITT)
Other third-party libraries:
Intel IPP: 2021.12.0 [2021.12.0]
at: E:/HW-Traffic/5_Source/Source/opencv-4.11.0/build/3rdparty/ippicv/ippicv_win/icv
Intel IPP IW: sources (2021.12.0)
at: E:/HW-Traffic/5_Source/Source/opencv-4.11.0/build/3rdparty/ippicv/ippicv_win/iw
Lapack: NO
Eigen: YES (ver ..)
Custom HAL: NO
Protobuf: build (3.19.1)
Flatbuffers: builtin/3rdparty (23.5.9)
NVIDIA CUDA: YES (ver 12.8, CUFFT CUBLAS NVCUVID NVCUVENC FAST_MATH)
NVIDIA GPU arch: 75 86 89 120
NVIDIA PTX archs: 90
cuDNN: YES (ver 9.8.0)
OpenCL: YES (NVD3D11)
Include path: E:/HW-Traffic/5_Source/Source/opencv-4.11.0/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python (for build): NO
Install to: E:/HW-Traffic/5_Source/Source/opencv-4.11.0/build/install
-----------------------------------------------------------------
Configuring done (8.6s)
posted on 2025-04-24 18:09 Sam.Richard 阅读(542) 评论(0) 收藏 举报
浙公网安备 33010602011771号