freetype,harfbuzz,opencv-contribute编译

1. 编译安装freetype

下载
freetype,harfbuzz,opencv-contribute编译_第1张图片

默认Configure,Generate,OpenProject. 需要生成Debug和Release. VS2019 选择ALL_BUILD后INSTALL,得到相应的include和lib.
系统变量添加变量FREETYPE_DIR,目录与CMAKE_INSTALL_PREFIX保持一致.

2.编译安装harfbuzz

下载
初次Configure后,钩选HB_HAVE_FREETYE,再次Configure.
freetype,harfbuzz,opencv-contribute编译_第2张图片

Configure后再次设置freetype变量如下:

freetype,harfbuzz,opencv-contribute编译_第3张图片

系统变量添加变量HARFBUZZ_DIR,目录与CMAKE_INSTALL_PREFIX保持一致.

3.修改modules/freetype/CMakeLists.txt

opencv_contrib-x.x.x版本与opencv版本一致,
下载
修改如下内容:

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()

4.编译安装OpenCV

初次Configure后,选择contrib模块路径,同时把模块集合在BUILD_opencv_world上,再Configure。
freetype,harfbuzz,opencv-contribute编译_第4张图片

再configure,会出现contrib里的module,已经出现freetype. 如果没有正确出现,可以勾选Cmake上的Advanced把相关harfbuzz和freetype的路径配置好。
freetype,harfbuzz,opencv-contribute编译_第5张图片

Configure直至没有出现红色警示,点击Genrate,Open Project.

5.VS里ALL_BUILD, INSTALL. 会在构建文件夹的install目录下生成所需的include,和lib和dll.

6.使用:vs2019的项目配置opencv环境.

VS添加工程,配置环境:
a.属性VC++目录包含目录,然后将OpenCV的三个包含目录添加进去:
D:\XXX\opencv\build\include
D:\ XXX \opencv\build\include\opencv
D:\ XXX \opencv\build\include\opencv2\include
b.属性VC++目录库目录,添加OpenCV的库目录:
D:\ XXX \opencv\build\x64\vc15\lib
添加编译好的头文件和lib.
c. 属性链接器输入附加依赖项,添加lib文件
只输入文件名,如opencv_world411d.lib(debug), opencv_world411.lib(release)

若遇到CMakeDownloadLog.txt的问题,则用浏览器下载好log里面miss的文件放到log里相应的match目录即可。
freetype,harfbuzz,opencv-contribute编译_第6张图片

参考:

https://blog.csdn.net/Creama_/article/details/107238475
https://www.cnblogs.com/touch-skyer/p/14343791.html

你可能感兴趣的:(opencv,学习笔记,opencv,visual,studio,人工智能)